<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>8.1 Controllers 3.2.11</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="../css/main.css" type="text/css" media="screen, print" title="Style" charset="utf-8"/>
    <link rel="stylesheet" href="../css/pdf.css" type="text/css" media="print" title="PDF" charset="utf-8"/>
    <script type="text/javascript">
function addJsClass() {
    var classes = document.body.className.split(" ");
    classes.push("js");
    document.body.className = classes.join(" ");
}
    </script>
</head>

<body class="body" onload="addJsClass();">
<div id="navigation">
    <div class="navTitle">
        
        The Grails Framework
    </div>
    <div class="navLinks">
        <ul>
            <li>
                <div id="nav-summary" onmouseover="toggleNavSummary(false)" onmouseout="toggleNavSummary(true)">
                    <a href="../../guide/index.html" class="button">Table of contents</a>

                    <div id="nav-summary-childs" style="display:none;">
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/introduction.html"><strong>1</strong><span>Introduction</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/gettingStarted.html"><strong>2</strong><span>Getting Started</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/upgrading.html"><strong>3</strong><span>Upgrading</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/conf.html"><strong>4</strong><span>Configuration</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/commandLine.html"><strong>5</strong><span>The Command Line</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/profiles.html"><strong>6</strong><span>Application Profiles</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/GORM.html"><strong>7</strong><span>Object Relational Mapping (GORM)</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/theWebLayer.html"><strong>8</strong><span>The Web Layer</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/traits.html"><strong>9</strong><span>Traits</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/webServices.html"><strong>10</strong><span>Web Services</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/async.html"><strong>11</strong><span>Asynchronous Programming</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/validation.html"><strong>12</strong><span>Validation</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/services.html"><strong>13</strong><span>The Service Layer</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/staticTypeCheckingAndCompilation.html"><strong>14</strong><span>Static Type Checking And Compilation</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/testing.html"><strong>15</strong><span>Testing</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/i18n.html"><strong>16</strong><span>Internationalization</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/security.html"><strong>17</strong><span>Security</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/plugins.html"><strong>18</strong><span>Plugins</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/spring.html"><strong>19</strong><span>Grails and Spring</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/hibernate.html"><strong>20</strong><span>Grails and Hibernate</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/scaffolding.html"><strong>21</strong><span>Scaffolding</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/deployment.html"><strong>22</strong><span>Deployment</span></a>
                        </div>
                        
                        <div class="toc-item" style="margin-left:0"><a href="../../guide/contributing.html"><strong>23</strong><span>Contributing to Grails</span></a>
                        </div>
                        
                    </div>
                </div>
            </li>
            <li class="separator selected">
                <a id="ref-button" onclick="localToggle(); return false;" href="#">Quick Reference</a>
            </li>
        </ul>
    </div>


</div>

<table id="colset" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td id="col1">
            <div id="main" class="corner-all">

                
                    <div class="toc-item prev-left"><a href="../../guide/GORM.html">&lt;&lt; <strong>7</strong><span>Object Relational Mapping (GORM)</span></a></div>
                

                <span id='toggle-col1' class="toggle">(<a href="#" onclick="localToggle(); return false;">Quick Reference</a>)</span>

                
                    <div class="toc-item next-right"><a href="../../guide/traits.html"><strong>9</strong><span>Traits</span> >></a></div>
                


                <div class="project">
                    <h1>8.1 Controllers</h1>

                    <p><strong>Version:</strong> 3.2.11</p>
                </div>

                
                <div id="table-of-content">
                    <h2>Table of Contents</h2>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#understandingControllersAndActions"><strong>8.1</strong><span>Understanding Controllers and Actions</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#controllersAndScopes"><strong>8.2</strong><span>Controllers and Scopes</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#modelsAndViews"><strong>8.3</strong><span>Models and Views</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#redirectsAndChaining"><strong>8.4</strong><span>Redirects and Chaining</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#dataBinding"><strong>8.5</strong><span>Data Binding</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#jsonResponses"><strong>8.6</strong><span>Responding with JSON</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#moreOnJSONBuilder"><strong>8.7</strong><span>More on JSONBuilder</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#xmlResponses"><strong>8.8</strong><span>Responding with XML</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#uploadingFiles"><strong>8.9</strong><span>Uploading Files</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#commandObjects"><strong>8.10</strong><span>Command Objects</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#formtokens"><strong>8.11</strong><span>Handling Duplicate Form Submissions</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#typeConverters"><strong>8.12</strong><span>Simple Type Converters</span></a>
                    </div>
                    
                    <div class="toc-item" style="margin-left:0px"><a href="#controllerExceptionHandling"><strong>8.13</strong><span>Declarative Controller Exception Handling</span></a>
                    </div>
                    
                </div>
                

                
<a name="7.1 Controllers"><!-- Legacy link --></a>
<h2 id="controllers">8.1 Controllers</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="paragraph">
<p>A controller handles requests and creates or prepares the response. A controller can generate the response directly or delegate to a view. To create a controller, simply create a class whose name ends with <code>Controller</code> in the <code>grails-app/controllers</code> directory (in a subdirectory if it&#8217;s in a package).</p>
</div>
<div class="paragraph">
<p>The default <a href="#urlmappings">URL Mapping</a> configuration ensures that the first part of your controller name is mapped to a URI and each action defined within your controller maps to URIs within the controller name URI.</p>
</div>

<a name="7.1.1 Understanding Controllers and Actions"><!-- Legacy link --></a>
<h2 id="understandingControllersAndActions">8.1.1 Understanding Controllers and Actions</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/understandingControllersAndActions.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="sect3">
<h4 id="_creating_a_controller">Creating a controller</h4>
<div class="paragraph">
<p>Controllers can be created with the <a href="../ref/Command%20Line/create-controller.html">create-controller</a> or <a href="../ref/Command%20Line/generate-controller.html">generate-controller</a> command. For example try running the following command from the root of a Grails project:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="bash">grails create-controller book</code></pre>
</div>
</div>
<div class="paragraph">
<p>The command will create a controller at the location <code>grails-app/controllers/myapp/BookController.groovy</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> myapp

<span class="type">class</span> <span class="class">BookController</span> {

    <span class="keyword">def</span> <span class="function">index</span>() { }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>where "myapp" will be the name of your application, the default package name if one isn&#8217;t specified.</p>
</div>
<div class="paragraph">
<p><code>BookController</code> by default maps to the /book URI (relative to your application root).</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The <code>create-controller</code> and <code>generate-controller</code> commands are just for convenience and you can just as easily create controllers using your favorite text editor or IDE
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="_creating_actions">Creating Actions</h4>
<div class="paragraph">
<p>A controller can have multiple public action methods; each one maps to a URI:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">BookController</span> {

    <span class="keyword">def</span> <span class="function">list</span>() {

        <span class="comment">// do controller logic</span>
        <span class="comment">// create model</span>

        <span class="keyword">return</span> model
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This example maps to the <code>/book/list</code> URI by default thanks to the property being named <code>list</code>.</p>
</div>
</div>
<div class="sect3">
<h4 id="_the_default_action">The Default Action</h4>
<div class="paragraph">
<p>A controller has the concept of a default URI that maps to the root URI of the controller, for example <code>/book</code> for <code>BookController</code>. The action that is called when the default URI is requested is dictated by the following rules:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>If there is only one action, it&#8217;s the default</p>
</li>
<li>
<p>If you have an action named <code>index</code>, it&#8217;s the default</p>
</li>
<li>
<p>Alternatively you can set it explicitly with the <code>defaultAction</code> property:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="directive">static</span> defaultAction = <span class="string"><span class="delimiter">&quot;</span><span class="content">list</span><span class="delimiter">&quot;</span></span></code></pre>
</div>
</div>
</div>

<a name="7.1.2 Controllers and Scopes"><!-- Legacy link --></a>
<h2 id="controllersAndScopes">8.1.2 Controllers and Scopes</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/controllersAndScopes.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="sect3">
<h4 id="_available_scopes">Available Scopes</h4>
<div class="paragraph">
<p>Scopes are hash-like objects where you can store variables. The following scopes are available to controllers:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="../ref/Controllers/servletContext.html">servletContext</a> - Also known as application scope, this scope lets you share state across the entire web application. The servletContext is an instance of <a href="https://docs.oracle.com/javaee/7/api/javax/servlet/ServletContext.html">ServletContext</a></p>
</li>
<li>
<p><a href="../ref/Controllers/session.html">session</a> - The session allows associating state with a given user and typically uses cookies to associate a session with a client. The session object is an instance of <a href="https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpSession.html">HttpSession</a></p>
</li>
<li>
<p><a href="../ref/Controllers/request.html">request</a> - The request object allows the storage of objects for the current request only. The request object is an instance of <a href="https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletRequest.html">HttpServletRequest</a></p>
</li>
<li>
<p><a href="../ref/Controllers/params.html">params</a> - Mutable map of incoming request query string or POST parameters</p>
</li>
<li>
<p><a href="../ref/Controllers/flash.html">flash</a> - See below</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="_accessing_scopes">Accessing Scopes</h4>
<div class="paragraph">
<p>Scopes can be accessed using the variable names above in combination with Groovy&#8217;s array index operator, even on classes provided by the Servlet API such as the <a href="https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletRequest.html">HttpServletRequest</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">BookController</span> {
    <span class="keyword">def</span> <span class="function">find</span>() {
        <span class="keyword">def</span> findBy = params[<span class="string"><span class="delimiter">&quot;</span><span class="content">findBy</span><span class="delimiter">&quot;</span></span>]
        <span class="keyword">def</span> appContext = request[<span class="string"><span class="delimiter">&quot;</span><span class="content">foo</span><span class="delimiter">&quot;</span></span>]
        <span class="keyword">def</span> loggedUser = session[<span class="string"><span class="delimiter">&quot;</span><span class="content">logged_user</span><span class="delimiter">&quot;</span></span>]
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can also access values within scopes using the de-reference operator, making the syntax even more clear:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">BookController</span> {
    <span class="keyword">def</span> <span class="function">find</span>() {
        <span class="keyword">def</span> findBy = params.findBy
        <span class="keyword">def</span> appContext = request.foo
        <span class="keyword">def</span> loggedUser = session.logged_user
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This is one of the ways that Grails unifies access to the different scopes.</p>
</div>
</div>
<div class="sect3">
<h4 id="_using_flash_scope">Using Flash Scope</h4>
<div class="paragraph">
<p>Grails supports the concept of <a href="../ref/Controllers/flash.html">flash</a> scope as a temporary store to make attributes available for this request and the next request only. Afterwards the attributes are cleared. This is useful for setting a message directly before redirecting, for example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">delete</span>() {
    <span class="keyword">def</span> b = <span class="predefined-type">Book</span>.get(params.id)
    <span class="keyword">if</span> (!b) {
        flash.message = <span class="string"><span class="delimiter">&quot;</span><span class="content">User not found for id </span><span class="inline"><span class="inline-delimiter">${</span>params.id<span class="inline-delimiter">}</span></span><span class="delimiter">&quot;</span></span>
        redirect(<span class="key">action</span>:list)
    }
    ... <span class="comment">// remaining code</span>
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>When the <code>delete</code> action is requested, the <code>message</code> value will be in scope and can be used to display an information message. It will be removed from the <code>flash</code> scope after this second request.</p>
</div>
<div class="paragraph">
<p>Note that the attribute name can be anything you want, and the values are often strings used to display messages, but can be any object type.</p>
</div>
</div>
<div class="sect3">
<h4 id="_scoped_controllers">Scoped Controllers</h4>
<div class="paragraph">
<p>Newly created applications have the <code>grails.controllers.defaultScope</code> property set to a value of "singleton" in <code>application.yml</code>.  You may change this value to any
of the supported scopes listed below.  If the property is not assigned a value at all, controllers will default to "prototype" scope.</p>
</div>
<div class="paragraph">
<p>Supported controller scopes are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>prototype</code> (default) - A new controller will be created for each request (recommended for actions as Closure properties)</p>
</li>
<li>
<p><code>session</code> - One controller is created for the scope of a user session</p>
</li>
<li>
<p><code>singleton</code> - Only one instance of the controller ever exists (recommended for actions as methods)</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>To enable one of the scopes, add a static <code>scope</code> property to your class with one of the valid scope values listed above, for example</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="directive">static</span> scope = <span class="string"><span class="delimiter">&quot;</span><span class="content">singleton</span><span class="delimiter">&quot;</span></span></code></pre>
</div>
</div>
<div class="paragraph">
<p>You can define the default strategy in <code>application.yml</code> with the <code>grails.controllers.defaultScope</code> key, for example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="key">grails</span>:
    <span class="key">controllers</span>:
        <span class="key">defaultScope</span>: singleton</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Use scoped controllers wisely. For instance, we don&#8217;t recommend having any properties in a singleton-scoped controller since they will be shared for <em>all</em> requests.
</td>
</tr>
</table>
</div>
</div>

<a name="7.1.3 Models and Views"><!-- Legacy link --></a>
<h2 id="modelsAndViews">8.1.3 Models and Views</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/modelsAndViews.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="sect3">
<h4 id="_returning_the_model">Returning the Model</h4>
<div class="paragraph">
<p>A model is a Map that the view uses when rendering. The keys within that Map correspond to variable names accessible by the view. There are a couple of ways to return a model. First, you can explicitly return a Map instance:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">show</span>() {
    [<span class="key">book</span>: <span class="predefined-type">Book</span>.get(params.id)]
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The above does <em>not</em> reflect what you should use with the scaffolding views - see the <a href="scaffolding.html">scaffolding section</a> for more details.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>A more advanced approach is to return an instance of the Spring <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/ModelAndView.html">ModelAndView</a> class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">org.springframework.web.servlet.ModelAndView</span>

<span class="keyword">def</span> <span class="function">index</span>() {
    <span class="comment">// get some books just for the index page, perhaps your favorites</span>
    <span class="keyword">def</span> favoriteBooks = ...

    <span class="comment">// forward to the list view to show them</span>
    <span class="keyword">return</span> <span class="keyword">new</span> ModelAndView(<span class="string"><span class="delimiter">&quot;</span><span class="content">/book/list</span><span class="delimiter">&quot;</span></span>, [ bookList : favoriteBooks ])
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>One thing to bear in mind is that certain variable names can not be used in your model:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>attributes</code></p>
</li>
<li>
<p><code>application</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Currently, no error will be reported if you do use them, but this will hopefully change in a future version of Grails.</p>
</div>
</div>
<div class="sect3">
<h4 id="_selecting_the_view">Selecting the View</h4>
<div class="paragraph">
<p>In both of the previous two examples there was no code that specified which <a href="#gsp">view</a> to render. So how does Grails know which one to pick? The answer lies in the conventions. Grails will look for a view at the location <code>grails-app/views/book/show.gsp</code> for this <code>show</code> action:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">BookController</span> {
    <span class="keyword">def</span> <span class="function">show</span>() {
         [<span class="key">book</span>: <span class="predefined-type">Book</span>.get(params.id)]
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>To render a different view, use the <a href="../ref/Controllers/render.html">render</a> method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">show</span>() {
    <span class="keyword">def</span> map = [<span class="key">book</span>: <span class="predefined-type">Book</span>.get(params.id)]
    render(<span class="key">view</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">display</span><span class="delimiter">&quot;</span></span>, <span class="key">model</span>: map)
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In this case Grails will attempt to render a view at the location <code>grails-app/views/book/display.gsp</code>. Notice that Grails automatically qualifies the view location with the <code>book</code> directory of the <code>grails-app/views</code> directory. This is convenient, but to access shared views, you use an absolute path instead of a relative one:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">show</span>() {
    <span class="keyword">def</span> map = [<span class="key">book</span>: <span class="predefined-type">Book</span>.get(params.id)]
    render(<span class="key">view</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">/shared/display</span><span class="delimiter">&quot;</span></span>, <span class="key">model</span>: map)
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In this case Grails will attempt to render a view at the location <code>grails-app/views/shared/display.gsp</code>.</p>
</div>
<div class="paragraph">
<p>Grails also supports JSPs as views, so if a GSP isn&#8217;t found in the expected location but a JSP is, it will be used instead.</p>
</div>
</div>
<div class="sect3">
<h4 id="_selecting_views_for_namespaced_controllers">Selecting Views For Namespaced Controllers</h4>
<div class="paragraph">
<p>If a controller defines a namespace for itself with the <a href="#namespacedControllers">namespace</a> property that will affect the root directory in which Grails will look for views which are specified with a relative path.  The default root directory for views rendered by a namespaced controller is <code>grails-app/views/&lt;namespace name&gt;/&lt;controller name&gt;/</code>.  If the view is not found in the namespaced directory then Grails will fallback to looking for the view in the non-namespaced directory.</p>
</div>
<div class="paragraph">
<p>See the example below.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">ReportingController</span> {
    <span class="directive">static</span> namespace = <span class="string"><span class="delimiter">'</span><span class="content">business</span><span class="delimiter">'</span></span>

    <span class="keyword">def</span> <span class="function">humanResources</span>() {
        <span class="comment">// This will render grails-app/views/business/reporting/humanResources.gsp</span>
        <span class="comment">// if it exists.</span>

        <span class="comment">// If grails-app/views/business/reporting/humanResources.gsp does not</span>
        <span class="comment">// exist the fallback will be grails-app/views/reporting/humanResources.gsp.</span>

        <span class="comment">// The namespaced GSP will take precedence over the non-namespaced GSP.</span>

        [<span class="key">numberOfEmployees</span>: <span class="integer">9</span>]
    }


    <span class="keyword">def</span> <span class="function">accountsReceivable</span>() {
        <span class="comment">// This will render grails-app/views/business/reporting/numberCrunch.gsp</span>
        <span class="comment">// if it exists.</span>

        <span class="comment">// If grails-app/views/business/reporting/numberCrunch.gsp does not</span>
        <span class="comment">// exist the fallback will be grails-app/views/reporting/numberCrunch.gsp.</span>

        <span class="comment">// The namespaced GSP will take precedence over the non-namespaced GSP.</span>

        render <span class="key">view</span>: <span class="string"><span class="delimiter">'</span><span class="content">numberCrunch</span><span class="delimiter">'</span></span>, <span class="key">model</span>: [<span class="key">numberOfEmployees</span>: <span class="integer">13</span>]
    }
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_rendering_a_response">Rendering a Response</h4>
<div class="paragraph">
<p>Sometimes it&#8217;s easier (for example with Ajax applications) to render snippets of text or code to the response directly from the controller. For this, the highly flexible <code>render</code> method can be used:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">render <span class="string"><span class="delimiter">&quot;</span><span class="content">Hello World!</span><span class="delimiter">&quot;</span></span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The above code writes the text "Hello World!" to the response. Other examples include:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// write some markup</span>
render {
   <span class="keyword">for</span> (b <span class="keyword">in</span> books) {
      div(<span class="key">id</span>: b.id, b.title)
   }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// render a specific view</span>
render(<span class="key">view</span>: <span class="string"><span class="delimiter">'</span><span class="content">show</span><span class="delimiter">'</span></span>)</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// render a template for each item in a collection</span>
render(<span class="key">template</span>: <span class="string"><span class="delimiter">'</span><span class="content">book_template</span><span class="delimiter">'</span></span>, <span class="key">collection</span>: <span class="predefined-type">Book</span>.list())</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// render some text with encoding and content type</span>
render(<span class="key">text</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">&lt;xml&gt;some xml&lt;/xml&gt;</span><span class="delimiter">&quot;</span></span>, <span class="key">contentType</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">text/xml</span><span class="delimiter">&quot;</span></span>, <span class="key">encoding</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">UTF-8</span><span class="delimiter">&quot;</span></span>)</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you plan on using Groovy&#8217;s <code>MarkupBuilder</code> to generate HTML for use with the <code>render</code> method be careful of naming clashes between HTML elements and Grails tags, for example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">groovy.xml.MarkupBuilder</span>
...
def login() {
    <span class="keyword">def</span> writer = <span class="keyword">new</span> <span class="predefined-type">StringWriter</span>()
    <span class="keyword">def</span> builder = <span class="keyword">new</span> MarkupBuilder(writer)
    builder.html {
        head {
            title <span class="string"><span class="delimiter">'</span><span class="content">Log in</span><span class="delimiter">'</span></span>
        }
        body {
            h1 <span class="string"><span class="delimiter">'</span><span class="content">Hello</span><span class="delimiter">'</span></span>
            form {
            }
        }
    }

    <span class="keyword">def</span> html = writer.toString()
    render html
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will actually <a href="#tagsAsMethodCalls">call the form tag</a> (which will return some text that will be ignored by the <code>MarkupBuilder</code>). To correctly output a <code>&lt;form&gt;</code> element, use the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">login</span>() {
    <span class="comment">// ...</span>
    body {
        h1 <span class="string"><span class="delimiter">'</span><span class="content">Hello</span><span class="delimiter">'</span></span>
        builder.form {
        }
    }
    <span class="comment">// ...</span>
}</code></pre>
</div>
</div>
</div>

<a name="7.1.4 Redirects and Chaining"><!-- Legacy link --></a>
<h2 id="redirectsAndChaining">8.1.4 Redirects and Chaining</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/redirectsAndChaining.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="sect3">
<h4 id="_redirects">Redirects</h4>
<div class="paragraph">
<p>Actions can be redirected using the <a href="../ref/Controllers/redirect.html">redirect</a> controller method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">OverviewController</span> {

    <span class="keyword">def</span> <span class="function">login</span>() {}

    <span class="keyword">def</span> <span class="function">find</span>() {
        <span class="keyword">if</span> (!session.user)
            redirect(<span class="key">action</span>: <span class="string"><span class="delimiter">'</span><span class="content">login</span><span class="delimiter">'</span></span>)
            <span class="keyword">return</span>
        }
        ...
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Internally the <a href="../ref/Controllers/redirect.html">redirect</a> method uses the <a href="https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletResponse.html">HttpServletResponse</a> object&#8217;s <code>sendRedirect</code> method.</p>
</div>
<div class="paragraph">
<p>The <code>redirect</code> method expects one of:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The name of an action (and controller name if the redirect isn&#8217;t to an action in the current controller):</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// Also redirects to the index action in the home controller</span>
redirect(<span class="key">controller</span>: <span class="string"><span class="delimiter">'</span><span class="content">home</span><span class="delimiter">'</span></span>, <span class="key">action</span>: <span class="string"><span class="delimiter">'</span><span class="content">index</span><span class="delimiter">'</span></span>)</code></pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>A URI for a resource relative the application context path:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// Redirect to an explicit URI</span>
redirect(<span class="key">uri</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">/login.html</span><span class="delimiter">&quot;</span></span>)</code></pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>Or a full URL:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// Redirect to a URL</span>
redirect(<span class="key">url</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">http://grails.org</span><span class="delimiter">&quot;</span></span>)</code></pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>A <a href="GORM.html">domain class</a> instance:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// Redirect to the domain instance</span>
<span class="predefined-type">Book</span> book = ... <span class="comment">// obtain a domain instance</span>
redirect book</code></pre>
</div>
</div>
<div class="paragraph">
<p>In the above example Grails will construct a link using the domain class <code>id</code> (if present).</p>
</div>
<div class="paragraph">
<p>Parameters can optionally be passed from one action to the next using the <code>params</code> argument of the method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">redirect(<span class="key">action</span>: <span class="string"><span class="delimiter">'</span><span class="content">myaction</span><span class="delimiter">'</span></span>, <span class="key">params</span>: [<span class="key">myparam</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">myvalue</span><span class="delimiter">&quot;</span></span>])</code></pre>
</div>
</div>
<div class="paragraph">
<p>These parameters are made available through the <a href="../ref/Controllers/params.html">params</a> dynamic property that accesses request parameters. If a parameter is specified with the same name as a request parameter, the request parameter is overridden and the controller parameter is used.</p>
</div>
<div class="paragraph">
<p>Since the <code>params</code> object is a Map, you can use it to pass the current request parameters from one action to the next:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">redirect(<span class="key">action</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">next</span><span class="delimiter">&quot;</span></span>, <span class="key">params</span>: params)</code></pre>
</div>
</div>
<div class="paragraph">
<p>Finally, you can also include a fragment in the target URI:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">redirect(<span class="key">controller</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">test</span><span class="delimiter">&quot;</span></span>, <span class="key">action</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">show</span><span class="delimiter">&quot;</span></span>, <span class="key">fragment</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">profile</span><span class="delimiter">&quot;</span></span>)</code></pre>
</div>
</div>
<div class="paragraph">
<p>which will (depending on the URL mappings) redirect to something like "/myapp/test/show#profile".</p>
</div>
</div>
<div class="sect3">
<h4 id="_chaining">Chaining</h4>
<div class="paragraph">
<p>Actions can also be chained. Chaining allows the model to be retained from one action to the next. For example calling the <code>first</code> action in this action:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">ExampleChainController</span> {

    <span class="keyword">def</span> <span class="function">first</span>() {
        chain(<span class="key">action</span>: second, <span class="key">model</span>: [<span class="key">one</span>: <span class="integer">1</span>])
    }

    <span class="keyword">def</span> <span class="function">second</span> () {
        chain(<span class="key">action</span>: third, <span class="key">model</span>: [<span class="key">two</span>: <span class="integer">2</span>])
    }

    <span class="keyword">def</span> <span class="function">third</span>() {
        [<span class="key">three</span>: <span class="integer">3</span>])
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>results in the model:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">[<span class="key">one</span>: <span class="integer">1</span>, <span class="key">two</span>: <span class="integer">2</span>, <span class="key">three</span>: <span class="integer">3</span>]</code></pre>
</div>
</div>
<div class="paragraph">
<p>The model can be accessed in subsequent controller actions in the chain using the <code>chainModel</code> map. This dynamic property only exists in actions following the call to the <code>chain</code> method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">ChainController</span> {

    <span class="keyword">def</span> <span class="function">nextInChain</span>() {
        <span class="keyword">def</span> model = chainModel.myModel
        ...
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Like the <code>redirect</code> method you can also pass parameters to the <code>chain</code> method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">chain(<span class="key">action</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">action1</span><span class="delimiter">&quot;</span></span>, <span class="key">model</span>: [<span class="key">one</span>: <span class="integer">1</span>], <span class="key">params</span>: [<span class="key">myparam</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">param1</span><span class="delimiter">&quot;</span></span>])</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The chain method uses the HTTP session and hence should only be used if your application is stateful.
</td>
</tr>
</table>
</div>
</div>

<a name="7.1.6 Data Binding"><!-- Legacy link --></a>
<h2 id="dataBinding">8.1.5 Data Binding</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/dataBinding.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="paragraph">
<p>Data binding is the act of "binding" incoming request parameters onto the properties of an object or an entire graph of objects. Data binding should deal with all necessary type conversion since request parameters, which are typically delivered by a form submission, are always strings whilst the properties of a Groovy or Java object may well not be.</p>
</div>
<div class="sect3">
<h4 id="_map_based_binding">Map Based Binding</h4>
<div class="paragraph">
<p>The data binder is capable of converting and assigning values in a Map to properties of an object.  The binder will associate entries in the Map to properties of the object using the keys in the Map that have values which correspond to property names on the object.  The following code demonstrates the basics:</p>
</div>
<div class="listingblock">
<div class="title">grails-app/domain/Person.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">Person</span> {
    <span class="predefined-type">String</span> firstName
    <span class="predefined-type">String</span> lastName
    <span class="predefined-type">Integer</span> age
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> bindingMap = [<span class="key">firstName</span>: <span class="string"><span class="delimiter">'</span><span class="content">Peter</span><span class="delimiter">'</span></span>, <span class="key">lastName</span>: <span class="string"><span class="delimiter">'</span><span class="content">Gabriel</span><span class="delimiter">'</span></span>, <span class="key">age</span>: <span class="integer">63</span>]

<span class="keyword">def</span> person = <span class="keyword">new</span> Person(bindingMap)

<span class="keyword">assert</span> person.firstName == <span class="string"><span class="delimiter">'</span><span class="content">Peter</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> person.lastName == <span class="string"><span class="delimiter">'</span><span class="content">Gabriel</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> person.age == <span class="integer">63</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>To update properties of a domain object you may assign a Map to the <code>properties</code> property of the domain class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> bindingMap = [<span class="key">firstName</span>: <span class="string"><span class="delimiter">'</span><span class="content">Peter</span><span class="delimiter">'</span></span>, <span class="key">lastName</span>: <span class="string"><span class="delimiter">'</span><span class="content">Gabriel</span><span class="delimiter">'</span></span>, <span class="key">age</span>: <span class="integer">63</span>]

<span class="keyword">def</span> person = Person.get(someId)
person.properties = bindingMap

<span class="keyword">assert</span> person.firstName == <span class="string"><span class="delimiter">'</span><span class="content">Peter</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> person.lastName == <span class="string"><span class="delimiter">'</span><span class="content">Gabriel</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> person.age == <span class="integer">63</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The binder can populate a full graph of objects using Maps of Maps.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">Person</span> {
    <span class="predefined-type">String</span> firstName
    <span class="predefined-type">String</span> lastName
    <span class="predefined-type">Integer</span> age
    Address homeAddress
}

<span class="type">class</span> <span class="class">Address</span> {
    <span class="predefined-type">String</span> county
    <span class="predefined-type">String</span> country
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> bindingMap = [<span class="key">firstName</span>: <span class="string"><span class="delimiter">'</span><span class="content">Peter</span><span class="delimiter">'</span></span>, <span class="key">lastName</span>: <span class="string"><span class="delimiter">'</span><span class="content">Gabriel</span><span class="delimiter">'</span></span>, <span class="key">age</span>: <span class="integer">63</span>, <span class="key">homeAddress</span>: [<span class="key">county</span>: <span class="string"><span class="delimiter">'</span><span class="content">Surrey</span><span class="delimiter">'</span></span>, <span class="key">country</span>: <span class="string"><span class="delimiter">'</span><span class="content">England</span><span class="delimiter">'</span></span>] ]

<span class="keyword">def</span> person = <span class="keyword">new</span> Person(bindingMap)

<span class="keyword">assert</span> person.firstName == <span class="string"><span class="delimiter">'</span><span class="content">Peter</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> person.lastName == <span class="string"><span class="delimiter">'</span><span class="content">Gabriel</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> person.age == <span class="integer">63</span>
<span class="keyword">assert</span> person.homeAddress.county == <span class="string"><span class="delimiter">'</span><span class="content">Surrey</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> person.homeAddress.country == <span class="string"><span class="delimiter">'</span><span class="content">England</span><span class="delimiter">'</span></span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_binding_to_collections_and_maps">Binding To Collections And Maps</h4>
<div class="paragraph">
<p>The data binder can populate and update Collections and Maps.  The following code shows a simple example of populating a <code>List</code> of objects in a domain class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">Band</span> {
    <span class="predefined-type">String</span> name
    <span class="directive">static</span> hasMany = [<span class="key">albums</span>: Album]
    <span class="predefined-type">List</span> albums
}

<span class="type">class</span> <span class="class">Album</span> {
    <span class="predefined-type">String</span> title
    <span class="predefined-type">Integer</span> numberOfTracks
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> bindingMap = [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Genesis</span><span class="delimiter">'</span></span>,
                  <span class="string"><span class="delimiter">'</span><span class="content">albums[0]</span><span class="delimiter">'</span></span>: [<span class="key">title</span>: <span class="string"><span class="delimiter">'</span><span class="content">Foxtrot</span><span class="delimiter">'</span></span>, <span class="key">numberOfTracks</span>: <span class="integer">6</span>],
                  <span class="string"><span class="delimiter">'</span><span class="content">albums[1]</span><span class="delimiter">'</span></span>: [<span class="key">title</span>: <span class="string"><span class="delimiter">'</span><span class="content">Nursery Cryme</span><span class="delimiter">'</span></span>, <span class="key">numberOfTracks</span>: <span class="integer">7</span>]]

<span class="keyword">def</span> band = <span class="keyword">new</span> Band(bindingMap)

<span class="keyword">assert</span> band.name == <span class="string"><span class="delimiter">'</span><span class="content">Genesis</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> band.albums.size() == <span class="integer">2</span>
<span class="keyword">assert</span> band.albums[<span class="integer">0</span>].title == <span class="string"><span class="delimiter">'</span><span class="content">Foxtrot</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> band.albums[<span class="integer">0</span>].numberOfTracks == <span class="integer">6</span>
<span class="keyword">assert</span> band.albums[<span class="integer">1</span>].title == <span class="string"><span class="delimiter">'</span><span class="content">Nursery Cryme</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> band.albums[<span class="integer">1</span>].numberOfTracks == <span class="integer">7</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>That code would work in the same way if <code>albums</code> were an array instead of a <code>List</code>.</p>
</div>
<div class="paragraph">
<p>Note that when binding to a <code>Set</code> the structure of the <code>Map</code> being bound to the <code>Set</code> is the same as that of a <code>Map</code> being bound to a <code>List</code> but since a <code>Set</code> is unordered, the indexes don&#8217;t necessarily correspond to the order of elements in the <code>Set</code>.  In the code example above, if <code>albums</code> were a <code>Set</code> instead of a <code>List</code>, the <code>bindingMap</code> could look exactly the same but 'Foxtrot' might be the first album in the <code>Set</code> or it might be the second.  When updating existing elements in a <code>Set</code> the <code>Map</code> being assigned to the <code>Set</code> must have <code>id</code> elements in it which represent the element in the <code>Set</code> being updated, as in the following example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">/*
 * The value of the indexes 0 and 1 in albums[0] and albums[1] are arbitrary
 * values that can be anything as long as they are unique within the Map.
 * They do not correspond to the order of elements in albums because albums
 * is a Set.
 */</span>
<span class="keyword">def</span> bindingMap = [<span class="string"><span class="delimiter">'</span><span class="content">albums[0]</span><span class="delimiter">'</span></span>: [<span class="key">id</span>: <span class="integer">9</span>, <span class="key">title</span>: <span class="string"><span class="delimiter">'</span><span class="content">The Lamb Lies Down On Broadway</span><span class="delimiter">'</span></span>]
                  <span class="string"><span class="delimiter">'</span><span class="content">albums[1]</span><span class="delimiter">'</span></span>: [<span class="key">id</span>: <span class="integer">4</span>, <span class="key">title</span>: <span class="string"><span class="delimiter">'</span><span class="content">Selling England By The Pound</span><span class="delimiter">'</span></span>]]

<span class="keyword">def</span> band = Band.get(someBandId)

<span class="comment">/*
 * This will find the Album in albums that has an id of 9 and will set its title
 * to 'The Lamb Lies Down On Broadway' and will find the Album in albums that has
 * an id of 4 and set its title to 'Selling England By The Pound'.  In both
 * cases if the Album cannot be found in albums then the album will be retrieved
 * from the database by id, the Album will be added to albums and will be updated
 * with the values described above.  If a Album with the specified id cannot be
 * found in the database, then a binding error will be created and associated
 * with the band object.  More on binding errors later.
 */</span>
band.properties = bindingMap</code></pre>
</div>
</div>
<div class="paragraph">
<p>When binding to a <code>Map</code> the structure of the binding <code>Map</code> is the same as the structure of a <code>Map</code> used for binding to a <code>List</code> or a <code>Set</code> and the index inside of square brackets corresponds to the key in the <code>Map</code> being bound to.  See the following code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">Album</span> {
    <span class="predefined-type">String</span> title
    <span class="directive">static</span> hasMany = [<span class="key">players</span>: Player]
    <span class="predefined-type">Map</span> players
}

<span class="type">class</span> <span class="class">Player</span> {
    <span class="predefined-type">String</span> name
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> bindingMap = [<span class="key">title</span>: <span class="string"><span class="delimiter">'</span><span class="content">The Lamb Lies Down On Broadway</span><span class="delimiter">'</span></span>,
                  <span class="string"><span class="delimiter">'</span><span class="content">players[guitar]</span><span class="delimiter">'</span></span>: [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Steve Hackett</span><span class="delimiter">'</span></span>],
                  <span class="string"><span class="delimiter">'</span><span class="content">players[vocals]</span><span class="delimiter">'</span></span>: [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Peter Gabriel</span><span class="delimiter">'</span></span>],
                  <span class="string"><span class="delimiter">'</span><span class="content">players[keyboards]</span><span class="delimiter">'</span></span>: [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Tony Banks</span><span class="delimiter">'</span></span>]]

<span class="keyword">def</span> album = <span class="keyword">new</span> Album(bindingMap)

<span class="keyword">assert</span> album.title == <span class="string"><span class="delimiter">'</span><span class="content">The Lamb Lies Down On Broadway</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.size() == <span class="integer">3</span>
<span class="keyword">assert</span> album.players.guitar.name == <span class="string"><span class="delimiter">'</span><span class="content">Steve Hackett</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.vocals.name == <span class="string"><span class="delimiter">'</span><span class="content">Peter Gabriel</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.keyboards.name == <span class="string"><span class="delimiter">'</span><span class="content">Tony Banks</span><span class="delimiter">'</span></span></code></pre>
</div>
</div>
<div class="paragraph">
<p>When updating an existing <code>Map</code>, if the key specified in the binding <code>Map</code> does not exist in the <code>Map</code> being bound to then a new value will be created and added to the <code>Map</code> with the specified key as in the following example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> bindingMap = [<span class="key">title</span>: <span class="string"><span class="delimiter">'</span><span class="content">The Lamb Lies Down On Broadway</span><span class="delimiter">'</span></span>,
                  <span class="string"><span class="delimiter">'</span><span class="content">players[guitar]</span><span class="delimiter">'</span></span>: [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Steve Hackett</span><span class="delimiter">'</span></span>],
                  <span class="string"><span class="delimiter">'</span><span class="content">players[vocals]</span><span class="delimiter">'</span></span>: [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Peter Gabriel</span><span class="delimiter">'</span></span>],
                  <span class="string"><span class="delimiter">'</span><span class="content">players[keyboards]</span><span class="delimiter">'</span></span>: [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Tony Banks</span><span class="delimiter">'</span></span>]]

<span class="keyword">def</span> album = <span class="keyword">new</span> Album(bindingMap)

<span class="keyword">assert</span> album.title == <span class="string"><span class="delimiter">'</span><span class="content">The Lamb Lies Down On Broadway</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.size() == <span class="integer">3</span>
<span class="keyword">assert</span> album.players.guitar.name == <span class="string"><span class="delimiter">'</span><span class="content">Steve Hackett</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.vocals.name  == <span class="string"><span class="delimiter">'</span><span class="content">Peter Gabriel</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.keyboards.name  == <span class="string"><span class="delimiter">'</span><span class="content">Tony Banks</span><span class="delimiter">'</span></span>

<span class="keyword">def</span> updatedBindingMap = [<span class="string"><span class="delimiter">'</span><span class="content">players[drums]</span><span class="delimiter">'</span></span>: [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Phil Collins</span><span class="delimiter">'</span></span>],
                         <span class="string"><span class="delimiter">'</span><span class="content">players[keyboards]</span><span class="delimiter">'</span></span>: [<span class="key">name</span>: <span class="string"><span class="delimiter">'</span><span class="content">Anthony George Banks</span><span class="delimiter">'</span></span>]]

album.properties = updatedBindingMap

<span class="keyword">assert</span> album.title == <span class="string"><span class="delimiter">'</span><span class="content">The Lamb Lies Down On Broadway</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.size() == <span class="integer">4</span>
<span class="keyword">assert</span> album.players.guitar.name == <span class="string"><span class="delimiter">'</span><span class="content">Steve Hackett</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.vocals.name == <span class="string"><span class="delimiter">'</span><span class="content">Peter Gabriel</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.keyboards.name == <span class="string"><span class="delimiter">'</span><span class="content">Anthony George Banks</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> album.players.drums.name == <span class="string"><span class="delimiter">'</span><span class="content">Phil Collins</span><span class="delimiter">'</span></span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_binding_request_data_to_the_model">Binding Request Data to the Model</h4>
<div class="paragraph">
<p>The <a href="../ref/Controllers/params.html">params</a> object that is available in a controller has special behavior that helps convert dotted request parameter names into nested Maps that the data binder can work with.  For example, if a request includes request parameters named <code>person.homeAddress.country</code> and <code>person.homeAddress.city</code> with values 'USA' and 'St. Louis' respectively, <code>params</code> would include entries like these:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">[<span class="key">person</span>: [<span class="key">homeAddress</span>: [<span class="key">country</span>: <span class="string"><span class="delimiter">'</span><span class="content">USA</span><span class="delimiter">'</span></span>, <span class="key">city</span>: <span class="string"><span class="delimiter">'</span><span class="content">St. Louis</span><span class="delimiter">'</span></span>]]]</code></pre>
</div>
</div>
<div class="paragraph">
<p>There are two ways to bind request parameters onto the properties of a domain class. The first involves using a domain classes' Map constructor:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">save</span>() {
    <span class="keyword">def</span> b = <span class="keyword">new</span> <span class="predefined-type">Book</span>(params)
    b.save()
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The data binding happens within the code <code>new Book(params)</code>. By passing the <a href="../ref/Controllers/params.html">params</a> object to the domain class constructor Grails automatically recognizes that you are trying to bind from request parameters. So if we had an incoming request like:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code>/book/save?title=The%20Stand&amp;author=Stephen%20King</code></pre>
</div>
</div>
<div class="paragraph">
<p>Then the <code>title</code> and <code>author</code> request parameters would automatically be set on the domain class. You can use the <a href="../ref/Domain%20Classes/properties.html">properties</a> property to perform data binding onto an existing instance:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">save</span>() {
    <span class="keyword">def</span> b = <span class="predefined-type">Book</span>.get(params.id)
    b.properties = params
    b.save()
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This has the same effect as using the implicit constructor.</p>
</div>
<div class="paragraph">
<p>When binding an empty String (a String with no characters in it, not even spaces), the data binder will convert the empty String to null.  This simplifies the most common case where the intent is to treat an empty form field as having the value null since there isn&#8217;t a way to actually submit a null as a request parameter.  When this behavior is not desirable the application may assign the value directly.</p>
</div>
<div class="paragraph">
<p>The mass property binding mechanism will by default automatically trim all Strings at binding time.  To disable this behavior set the <code>grails.databinding.trimStrings</code> property to false in <code>grails-app/conf/application.groovy</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// the default value is true</span>
grails.databinding.trimStrings = <span class="predefined-constant">false</span>

<span class="comment">// ...</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The mass property binding mechanism will by default automatically convert all empty Strings to null at binding time.  To disable this behavior set the <code>grails.databinding.convertEmptyStringsToNull</code> property to false in <code>grails-app/conf/application.groovy</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// the default value is true</span>
grails.databinding.convertEmptyStringsToNull = <span class="predefined-constant">false</span>

<span class="comment">// ...</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The order of events is that the String trimming happens and then null conversion happens so if <code>trimStrings</code> is <code>true</code> and <code>convertEmptyStringsToNull</code> is <code>true</code>, not only will empty Strings be converted to null but also blank Strings.  A blank String is any String such that the <code>trim()</code> method returns an empty String.</p>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
These forms of data binding in Grails are very convenient, but also indiscriminate. In other words, they will bind <em>all</em> non-transient, typed instance properties of the target object, including ones that you may not want bound. Just because the form in your UI doesn&#8217;t submit all the properties, an attacker can still send malign data via a raw HTTP request. Fortunately, Grails also makes it easy to protect against such attacks - see the section titled "Data Binding and Security concerns" for more information.
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="_data_binding_and_single_ended_associations">Data binding and Single-ended Associations</h4>
<div class="paragraph">
<p>If you have a <code>one-to-one</code> or <code>many-to-one</code> association you can use Grails' data binding capability to update these relationships too. For example if you have an incoming request such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code>/book/save?author.id=20</code></pre>
</div>
</div>
<div class="paragraph">
<p>Grails will automatically detect the <code>.id</code> suffix on the request parameter and look up the <code>Author</code> instance for the given id when doing data binding such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> b = <span class="keyword">new</span> <span class="predefined-type">Book</span>(params)</code></pre>
</div>
</div>
<div class="paragraph">
<p>An association property can be set to <code>null</code> by passing the literal <code>String</code> "null". For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code>/book/save?author.id=null</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_data_binding_and_many_ended_associations">Data Binding and Many-ended Associations</h4>
<div class="paragraph">
<p>If you have a one-to-many or many-to-many association there are different techniques for data binding depending of the association type.</p>
</div>
<div class="paragraph">
<p>If you have a <code>Set</code> based association (the default for a <code>hasMany</code>) then the simplest way to populate an association is to send a list of identifiers. For example consider the usage of <code>&lt;g:select&gt;</code> below:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:select</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">from</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${Book.list()}</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">size</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">5</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">multiple</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">yes</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">optionKey</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">id</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${author?.books}</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This produces a select box that lets you select multiple values. In this case if you submit the form Grails will automatically use the identifiers from the select box to populate the <code>books</code> association.</p>
</div>
<div class="paragraph">
<p>However, if you have a scenario where you want to update the properties of the associated objects the this technique won&#8217;t work. Instead you use the subscript operator:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:textField</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[0].title</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">the Stand</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;g:textField</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[1].title</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">the Shining</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>However, with <code>Set</code> based association it is critical that you render the mark-up in the same order that you plan to do the update in. This is because a <code>Set</code> has no concept of order, so although we&#8217;re referring to <code>books[0]</code> and <code>books[1]</code> it is not guaranteed that the order of the association will be correct on the server side unless you apply some explicit sorting yourself.</p>
</div>
<div class="paragraph">
<p>This is not a problem if you use <code>List</code> based associations, since a <code>List</code> has a defined order and an index you can refer to. This is also true of <code>Map</code> based associations.</p>
</div>
<div class="paragraph">
<p>Note also that if the association you are binding to has a size of two and you refer to an element that is outside the size of association:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:textField</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[0].title</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">the Stand</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;g:textField</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[1].title</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">the Shining</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
<span class="tag">&lt;g:textField</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[2].title</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">Red Madder</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Then Grails will automatically create a new instance for you at the defined position.</p>
</div>
<div class="paragraph">
<p>You can bind existing instances of the associated type to a <code>List</code> using the same <code>.id</code> syntax as you would use with a single-ended association. For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:select</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[0].id</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">from</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${bookList}</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${author?.books[0]?.id}</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>

<span class="tag">&lt;g:select</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[1].id</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">from</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${bookList}</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${author?.books[1]?.id}</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>

<span class="tag">&lt;g:select</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[2].id</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">from</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${bookList}</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${author?.books[2]?.id}</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Would allow individual entries in the <code>books List</code> to be selected separately.</p>
</div>
<div class="paragraph">
<p>Entries at particular indexes can be removed in the same way too. For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:select</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[0].id</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">from</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${Book.list()}</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${author?.books[0]?.id}</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">noSelection</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">['null': '']</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Will render a select box that will remove the association at <code>books[0]</code> if the empty option is chosen.</p>
</div>
<div class="paragraph">
<p>Binding to a <code>Map</code> property works the same way except that the list index in the parameter name is replaced by the map key:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:select</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">images[cover].id</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">from</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${Image.list()}</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${book?.images[cover]?.id}</span><span class="delimiter">&quot;</span></span>
          <span class="attribute-name">noSelection</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">['null': '']</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>This would bind the selected image into the <code>Map</code> property <code>images</code> under a key of <code>"cover"</code>.</p>
</div>
<div class="paragraph">
<p>When binding to Maps, Arrays and Collections the data binder will automatically grow the size of the collections as necessary.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The default limit to how large the binder will grow a collection is 256. If the data binder encounters an entry that requires the collection be grown beyond that limit, the entry is ignored.  The limit may be configured by assigning a value to the <code>grails.databinding.autoGrowCollectionLimit</code> property in <code>application.groovy</code>.
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="title">grails-app/conf/application.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// the default value is 256</span>
grails.databinding.autoGrowCollectionLimit = <span class="integer">128</span>

<span class="comment">// ...</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_data_binding_with_multiple_domain_classes">Data binding with Multiple domain classes</h4>
<div class="paragraph">
<p>It is possible to bind data to multiple domain objects from the <a href="../ref/Controllers/params.html">params</a> object.</p>
</div>
<div class="paragraph">
<p>For example so you have an incoming request to:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="bash">/book/save?book.title=The%20Stand&amp;author.name=Stephen%20King</code></pre>
</div>
</div>
<div class="paragraph">
<p>You&#8217;ll notice the difference with the above request is that each parameter has a prefix such as <code>author.</code> or <code>book.</code> which is used to isolate which parameters belong to which type. Grails' <code>params</code> object is like a multi-dimensional hash and you can index into it to isolate only a subset of the parameters to bind.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> b = <span class="keyword">new</span> <span class="predefined-type">Book</span>(params.book)</code></pre>
</div>
</div>
<div class="paragraph">
<p>Notice how we use the prefix before the first dot of the <code>book.title</code> parameter to isolate only parameters below this level to bind. We could do the same with an <code>Author</code> domain class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> a = <span class="keyword">new</span> Author(params.author)</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_data_binding_and_action_arguments">Data Binding and Action Arguments</h4>
<div class="paragraph">
<p>Controller action arguments are subject to request parameter data binding.  There are 2 categories of controller action arguments.  The first category is command objects.  Complex types are treated as command objects.  See the <a href="theWebLayer.html#commandObjects">Command Objects</a> section of the user guide for details.  The other category is basic object types.  Supported types are the 8 primitives, their corresponding type wrappers and <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html">java.lang.String</a>.  The default behavior is to map request parameters to action arguments by name:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">AccountingController</span> {

   <span class="comment">// accountNumber will be initialized with the value of params.accountNumber</span>
   <span class="comment">// accountType will be initialized with params.accountType</span>
   <span class="keyword">def</span> <span class="function">displayInvoice</span>(<span class="predefined-type">String</span> accountNumber, <span class="type">int</span> accountType) {
       <span class="comment">// ...</span>
   }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For primitive arguments and arguments which are instances of any of the primitive type wrapper classes a type conversion has to be carried out before the request parameter value can be bound to the action argument.  The type conversion happens automatically.  In a case like the example shown above, the <code>params.accountType</code> request parameter has to be converted to an <code>int</code>.  If type conversion fails for any reason, the argument will have its default value per normal Java behavior (null for type wrapper references, false for booleans and zero for numbers) and a corresponding error will be added to the <code>errors</code> property of the defining controller.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="bash">/accounting/displayInvoice?accountNumber=B59786&amp;accountType=bogusValue</code></pre>
</div>
</div>
<div class="paragraph">
<p>Since "bogusValue" cannot be converted to type int, the value of accountType will be zero, the controller&#8217;s <code>errors.hasErrors()</code> will be true, the controller&#8217;s <code>errors.errorCount</code> will be equal to 1 and the controller&#8217;s <code>errors.getFieldError('accountType')</code> will contain the corresponding error.</p>
</div>
<div class="paragraph">
<p>If the argument name does not match the name of the request parameter then the <code>@grails.web.RequestParameter</code> annotation may be applied to an argument to express the name of the request parameter which should be bound to that argument:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.web.RequestParameter</span>

<span class="type">class</span> <span class="class">AccountingController</span> {

   <span class="comment">// mainAccountNumber will be initialized with the value of params.accountNumber</span>
   <span class="comment">// accountType will be initialized with params.accountType</span>
   <span class="keyword">def</span> <span class="function">displayInvoice</span>(<span class="annotation">@RequestParameter</span>(<span class="string"><span class="delimiter">'</span><span class="content">accountNumber</span><span class="delimiter">'</span></span>) <span class="predefined-type">String</span> mainAccountNumber, <span class="type">int</span> accountType) {
       <span class="comment">// ...</span>
   }
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_data_binding_and_type_conversion_errors">Data binding and type conversion errors</h4>
<div class="paragraph">
<p>Sometimes when performing data binding it is not possible to convert a particular String into a particular target type. This results in a type conversion error. Grails will retain type conversion errors inside the <a href="../ref/Domain%20Classes/errors.html">errors</a> property of a Grails domain class. For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">Book</span> {
    ...
    URL publisherURL
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Here we have a domain class <code>Book</code> that uses the <code>java.net.URL</code> class to represent URLs. Given an incoming request such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="bash">/book/save?publisherURL=a-bad-url</code></pre>
</div>
</div>
<div class="paragraph">
<p>it is not possible to bind the string <code>a-bad-url</code> to the <code>publisherURL</code> property as a type mismatch error occurs. You can check for these like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> b = <span class="keyword">new</span> <span class="predefined-type">Book</span>(params)

<span class="keyword">if</span> (b.hasErrors()) {
    println <span class="string"><span class="delimiter">&quot;</span><span class="content">The value </span><span class="inline"><span class="inline-delimiter">${</span>b.errors.getFieldError(<span class="string"><span class="delimiter">'</span><span class="content">publisherURL</span><span class="delimiter">'</span></span>).rejectedValue<span class="inline-delimiter">}</span></span><span class="delimiter">&quot;</span></span> +
            <span class="string"><span class="delimiter">&quot;</span><span class="content"> is not a valid URL!</span><span class="delimiter">&quot;</span></span>
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Although we have not yet covered error codes (for more information see the section on <a href="validation.html">validation</a>), for type conversion errors you would want a message from the <code>grails-app/i18n/messages.properties</code> file to use for the error. You can use a generic error message handler such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">typeMismatch.java.net.URL=The field {<span class="integer">0</span>} is not a valid <span class="predefined-type">URL</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Or a more specific one:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">typeMismatch.Book.publisherURL=The publisher <span class="predefined-type">URL</span> you specified is not a valid <span class="predefined-type">URL</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_the_bindusing_annotation">The BindUsing Annotation</h4>
<div class="paragraph">
<p>The <a href="http://docs.grails.org/3.2.11/api/grails/databinding/BindUsing.html">BindUsing</a> annotation may be used to define a custom binding mechanism for a particular field in a class.  Any time data binding is being applied to the field the closure value of the annotation will be invoked with 2 arguments.  The first argument is the object that data binding is being applied to and the second argument is <a href="http://docs.grails.org/3.2.11/api/grails/databinding/DataBindingSource.html">DataBindingSource</a> which is the data source for the data binding.  The value returned from the closure will be bound to the property.  The following example would result in the upper case version of the <code>name</code> value in the source being applied to the <code>name</code> field during data binding.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.databinding.BindUsing</span>

<span class="type">class</span> <span class="class">SomeClass</span> {
    <span class="annotation">@BindUsing</span>({obj, source -&gt;

        <span class="comment">//source is DataSourceBinding which is similar to a Map</span>
        <span class="comment">//and defines getAt operation but source.name cannot be used here.</span>
        <span class="comment">//In order to get name from source use getAt instead as shown below.</span>

        source[<span class="string"><span class="delimiter">'</span><span class="content">name</span><span class="delimiter">'</span></span>]?.toUpperCase()
    })
    <span class="predefined-type">String</span> name
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Note that data binding is only possible when the name of the request parameter matches with the field name in the class.
Here, <code>name</code> from request parameters matches with <code>name</code> from <code>SomeClass</code>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <a href="http://docs.grails.org/3.2.11/api/grails/databinding/BindUsing.html">BindUsing</a> annotation may be used to define a custom binding mechanism for all of the fields on a particular class. When the annotation is applied to a class, the value assigned to the annotation should be a class which implements the <a href="http://docs.grails.org/3.2.11/api/grails/databinding/BindingHelper.html">BindingHelper</a> interface.  An instance of that class will be used any time a value is bound to a property in the class that this annotation has been applied to.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="annotation">@BindUsing</span>(SomeClassWhichImplementsBindingHelper)
<span class="type">class</span> <span class="class">SomeClass</span> {
    <span class="predefined-type">String</span> someProperty
    <span class="predefined-type">Integer</span> someOtherProperty
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_custom_data_converters">Custom Data Converters</h4>
<div class="paragraph">
<p>The binder will do a lot of type conversion automatically.  Some applications may want to define their own mechanism for converting values and a simple way to do this is to write a class which implements <a href="http://docs.grails.org/3.2.11/api/grails/databinding/converters/ValueConverter.html">ValueConverter</a> and register an instance of that class as a bean in the Spring application context.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.myapp.converters

<span class="keyword">import</span> <span class="include">grails.databinding.converters.ValueConverter</span>

<span class="comment">/**
 * A custom converter which will convert String of the
 * form 'city:state' into an Address object.
 */</span>
<span class="type">class</span> <span class="class">AddressValueConverter</span> <span class="directive">implements</span> ValueConverter {

    <span class="type">boolean</span> canConvert(value) {
        value <span class="keyword">instanceof</span> <span class="predefined-type">String</span>
    }

    <span class="keyword">def</span> <span class="function">convert</span>(value) {
        <span class="keyword">def</span> pieces = value.split(<span class="string"><span class="delimiter">'</span><span class="content">:</span><span class="delimiter">'</span></span>)
        <span class="keyword">new</span> com.myapp.Address(<span class="key">city</span>: pieces[<span class="integer">0</span>], <span class="key">state</span>: pieces[<span class="integer">1</span>])
    }

    <span class="predefined-type">Class</span>&lt;?&gt; getTargetType() {
        com.myapp.Address
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>An instance of that class needs to be registered as a bean in the Spring application context.  The bean name is not important.  All beans that implemented ValueConverter will be automatically plugged in to the data binding process.</p>
</div>
<div class="listingblock">
<div class="title">grails-app/conf/spring/resources.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">beans = {
    addressConverter com.myapp.converters.AddressValueConverter
    <span class="comment">// ...</span>
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">Person</span> {
    <span class="predefined-type">String</span> firstName
    Address homeAddress
}

<span class="type">class</span> <span class="class">Address</span> {
    <span class="predefined-type">String</span> city
    <span class="predefined-type">String</span> state
}

<span class="keyword">def</span> person = <span class="keyword">new</span> Person()
person.properties = [<span class="key">firstName</span>: <span class="string"><span class="delimiter">'</span><span class="content">Jeff</span><span class="delimiter">'</span></span>, <span class="key">homeAddress</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">O'Fallon:Missouri</span><span class="delimiter">&quot;</span></span>]
<span class="keyword">assert</span> person.firstName == <span class="string"><span class="delimiter">'</span><span class="content">Jeff</span><span class="delimiter">'</span></span>
<span class="keyword">assert</span> person.homeAddress.city = <span class="string"><span class="delimiter">&quot;</span><span class="content">O'Fallon</span><span class="delimiter">&quot;</span></span>
<span class="keyword">assert</span> person.homeAddress.state = <span class="string"><span class="delimiter">'</span><span class="content">Missouri</span><span class="delimiter">'</span></span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_date_formats_for_data_binding">Date Formats For Data Binding</h4>
<div class="paragraph">
<p>A custom date format may be specified to be used when binding a String to a Date value by applying the <a href="http://docs.grails.org/3.2.11/api/grails/databinding/BindingFormat.html">BindingFormat</a> annotation to a Date field.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.databinding.BindingFormat</span>

<span class="type">class</span> <span class="class">Person</span> {
    <span class="annotation">@BindingFormat</span>(<span class="string"><span class="delimiter">'</span><span class="content">MMddyyyy</span><span class="delimiter">'</span></span>)
    <span class="predefined-type">Date</span> birthDate
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>A global setting may be configured in <code>application.groovy</code> to define date formats which will be used application wide when binding to Date.</p>
</div>
<div class="listingblock">
<div class="title">grails-app/conf/application.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">grails.databinding.dateFormats = [<span class="string"><span class="delimiter">'</span><span class="content">MMddyyyy</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">yyyy-MM-dd HH:mm:ss.S</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">yyyy-MM-dd'T'hh:mm:ss'Z'</span><span class="delimiter">&quot;</span></span>]</code></pre>
</div>
</div>
<div class="paragraph">
<p>The formats specified in <code>grails.databinding.dateFormats</code> will be attempted in the order in which they are included in the List.  If a property is marked with <code>@BindingFormat</code>, the <code>@BindingFormat</code> will take precedence over the values specified in <code>grails.databinding.dateFormats</code>.</p>
</div>
<div class="paragraph">
<p>The formats configured by default are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>yyyy-MM-dd HH:mm:ss.S</code></p>
</li>
<li>
<p><code>yyyy-MM-dd&#8217;T&#8217;hh:mm:ss&#8217;Z'</code></p>
</li>
<li>
<p><code>yyyy-MM-dd HH:mm:ss.S z</code></p>
</li>
<li>
<p><code>yyyy-MM-dd&#8217;T&#8217;HH:mm:ss.SSSX</code></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="_custom_formatted_converters">Custom Formatted Converters</h4>
<div class="paragraph">
<p>You may supply your own handler for the <a href="http://docs.grails.org/3.2.11/api/grails/databinding/BindingFormat.html">BindingFormat</a> annotation by writing a class which implements the <a href="http://docs.grails.org/3.2.11/api/grails/databinding/converters/FormattedValueConverter.html">FormattedValueConverter</a> interface and registering an instance of that class as a bean in the Spring application context.  Below is an example of a trivial custom String formatter that might convert the case of a String based on the value assigned to the BindingFormat annotation.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.myapp.converters

<span class="keyword">import</span> <span class="include">grails.databinding.converters.FormattedValueConverter</span>

<span class="type">class</span> <span class="class">FormattedStringValueConverter</span> <span class="directive">implements</span> FormattedValueConverter {
    <span class="keyword">def</span> <span class="function">convert</span>(value, <span class="predefined-type">String</span> format) {
        <span class="keyword">if</span>(<span class="string"><span class="delimiter">'</span><span class="content">UPPERCASE</span><span class="delimiter">'</span></span> == format) {
            value = value.toUpperCase()
        } <span class="keyword">else</span> <span class="keyword">if</span>(<span class="string"><span class="delimiter">'</span><span class="content">LOWERCASE</span><span class="delimiter">'</span></span> == format) {
            value = value.toLowerCase()
        }
        value
    }

    <span class="predefined-type">Class</span> getTargetType() {
        <span class="comment">// specifies the type to which this converter may be applied</span>
        <span class="predefined-type">String</span>
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>An instance of that class needs to be registered as a bean in the Spring application context.  The bean name is not important.  All beans that implemented FormattedValueConverter will be automatically plugged in to the data binding process.</p>
</div>
<div class="listingblock">
<div class="title">grails-app/conf/spring/resources.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">beans = {
    formattedStringConverter com.myapp.converters.FormattedStringValueConverter
    <span class="comment">// ...</span>
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>With that in place the <code>BindingFormat</code> annotation may be applied to String fields to inform the data binder to take advantage of the custom converter.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.databinding.BindingFormat</span>

<span class="type">class</span> <span class="class">Person</span> {
    <span class="annotation">@BindingFormat</span>(<span class="string"><span class="delimiter">'</span><span class="content">UPPERCASE</span><span class="delimiter">'</span></span>)
    <span class="predefined-type">String</span> someUpperCaseString

    <span class="annotation">@BindingFormat</span>(<span class="string"><span class="delimiter">'</span><span class="content">LOWERCASE</span><span class="delimiter">'</span></span>)
    <span class="predefined-type">String</span> someLowerCaseString

    <span class="predefined-type">String</span> someOtherString
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_localized_binding_formats">Localized Binding Formats</h4>
<div class="paragraph">
<p>The <code>BindingFormat</code> annotation supports localized format strings by using the optional <code>code</code> attribute.  If a value is assigned to the code attribute that value will be used as the message code to retrieve the binding format string from the <code>messageSource</code> bean in the Spring application context and that lookup will be localized.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">import</span> <span class="include">grails.databinding.BindingFormat</span>

<span class="type">class</span> <span class="class">Person</span> {
    <span class="annotation">@BindingFormat</span>(code=<span class="string"><span class="delimiter">'</span><span class="content">date.formats.birthdays</span><span class="delimiter">'</span></span>)
    <span class="predefined-type">Date</span> birthDate
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="error">#</span> grails-app/conf/i18n/messages.properties
date.formats.birthdays=MMddyyyy</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="error">#</span> grails-app/conf/i18n/messages_es.properties
date.formats.birthdays=ddMMyyyy</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_structured_data_binding_editors">Structured Data Binding Editors</h4>
<div class="paragraph">
<p>A structured data binding editor is a helper class which can bind structured request parameters to a property.  The common use case for structured binding is binding to a <code>Date</code> object which might be constructed from several smaller pieces of information contained in several request parameters with names like <code>birthday_month</code>, <code>birthday_date</code> and <code>birthday_year</code>.  The structured editor would retrieve all of those individual pieces of information and use them to construct a <code>Date</code>.</p>
</div>
<div class="paragraph">
<p>The framework provides a structured editor for binding to <code>Date</code> objects.  An application may register its own structured editors for whatever types are appropriate.  Consider the following classes:</p>
</div>
<div class="listingblock">
<div class="title">src/main/groovy/databinding/Gadget.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> databinding

<span class="type">class</span> <span class="class">Gadget</span> {
    <span class="predefined-type">Shape</span> expandedShape
    <span class="predefined-type">Shape</span> compressedShape
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">src/main/groovy/databinding/Shape.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> databinding

<span class="type">class</span> <span class="class">Shape</span> {
    <span class="type">int</span> area
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>A <code>Gadget</code> has 2 <code>Shape</code> fields.  A <code>Shape</code> has an <code>area</code> property.  It may be that the application wants to accept request parameters like <code>width</code> and <code>height</code> and use those to calculate the <code>area</code> of a <code>Shape</code> at binding time.  A structured binding editor is well suited for that.</p>
</div>
<div class="paragraph">
<p>The way to register a structured editor with the data binding process is to add an instance of the <a href="http://docs.grails.org/3.2.11/api/grails/databinding/TypedStructuredBindingEditor.html">grails.databinding.TypedStructuredBindingEditor</a> interface to the Spring application context.  The easiest way to implement the <code>TypedStructuredBindingEditor</code> interface is to extend the <a href="http://docs.grails.org/3.2.11/api/org/grails/databinding/converters/AbstractStructuredDateBindingEditor.html">org.grails.databinding.converters.AbstractStructuredBindingEditor</a> abstract class and override the <code>getPropertyValue</code> method as shown below:</p>
</div>
<div class="listingblock">
<div class="title">src/main/groovy/databinding/converters/StructuredShapeEditor.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> databinding.converters

<span class="keyword">import</span> <span class="include">databinding.Shape</span>

<span class="keyword">import</span> <span class="include">org.grails.databinding.converters.AbstractStructuredBindingEditor</span>

<span class="type">class</span> <span class="class">StructuredShapeEditor</span> <span class="directive">extends</span> AbstractStructuredBindingEditor&lt;<span class="predefined-type">Shape</span>&gt; {

    <span class="directive">public</span> <span class="predefined-type">Shape</span> getPropertyValue(<span class="predefined-type">Map</span> values) {
        <span class="comment">// retrieve the individual values from the Map</span>
        <span class="keyword">def</span> width = values.width <span class="keyword">as</span> <span class="type">int</span>
        <span class="keyword">def</span> height = values.height <span class="keyword">as</span> <span class="type">int</span>

        <span class="comment">// use the values to calculate the area of the Shape</span>
        <span class="keyword">def</span> area = width * height

        <span class="comment">// create and return a Shape with the appropriate area</span>
        <span class="keyword">new</span> <span class="predefined-type">Shape</span>(<span class="key">area</span>: area)
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>An instance of that class needs to be registered with the Spring application context:</p>
</div>
<div class="listingblock">
<div class="title">grails-app/conf/spring/resources.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">beans = {
    shapeEditor databinding.converters.StructuredShapeEditor
    <span class="comment">// ...</span>
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>When the data binder binds to an instance of the <code>Gadget</code> class it will check to see if there are request parameters with names <code>compressedShape</code> and <code>expandedShape</code> which have a value of "struct" and if they do exist, that will trigger the use of the <code>StructuredShapeEditor</code>.  The individual components of the structure need to have parameter names of the form propertyName_structuredElementName.  In the case of the <code>Gadget</code> class above that would mean that the <code>compressedShape</code> request parameter should have a value of "struct" and the <code>compressedShape_width</code> and <code>compressedShape_height</code> parameters should have values which represent the width and the height of the compressed <code>Shape</code>.  Similarly, the <code>expandedShape</code> request parameter should have a value of "struct" and the <code>expandedShape_width</code> and <code>expandedShape_height</code> parameters should have values which represent the width and the height of the expanded <code>Shape</code>.</p>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/demo/DemoController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">DemoController</span> {

    <span class="keyword">def</span> <span class="function">createGadget</span>(Gadget gadget) {
        <span class="comment">/*
        /demo/createGadget?expandedShape=struct&amp;expandedShape_width=80&amp;expandedShape_height=30
                          &amp;compressedShape=struct&amp;compressedShape_width=10&amp;compressedShape_height=3

        */</span>

        <span class="comment">// with the request parameters shown above gadget.expandedShape.area would be 2400</span>
        <span class="comment">// and gadget.compressedShape.area would be 30</span>
        <span class="comment">// ...</span>
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Typically the request parameters with "struct" as their value would be represented by hidden form fields.</p>
</div>
</div>
<div class="sect3">
<h4 id="_data_binding_event_listeners">Data Binding Event Listeners</h4>
<div class="paragraph">
<p>The <a href="http://docs.grails.org/3.2.11/api/grails/databinding/events/DataBindingListener.html">DataBindingListener</a> interface provides a mechanism for listeners to be notified of data binding events.  The interface looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> grails.databinding.events;

<span class="keyword">import</span> <span class="include">grails.databinding.errors.BindingError</span>;

<span class="comment">/**
 * A listener which will be notified of events generated during data binding.
 *
 * @author Jeff Brown
 * @since 3.0
 * @see DataBindingListenerAdapter
 */</span>
<span class="directive">public</span> <span class="type">interface</span> DataBindingListener {

    <span class="comment">/**
     * @return true if the listener is interested in events for the specified type.
     */</span>
    <span class="type">boolean</span> supports(<span class="predefined-type">Class</span>&lt;?&gt; clazz);

    <span class="comment">/**
     * Called when data binding is about to start.
     *
     * @param target The object data binding is being imposed upon
     * @param errors the Spring Errors instance (a org.springframework.validation.BindingResult)
     * @return true if data binding should continue
     */</span>
    <span class="predefined-type">Boolean</span> beforeBinding(<span class="predefined-type">Object</span> target, <span class="predefined-type">Object</span> errors);

    <span class="comment">/**
     * Called when data binding is about to imposed on a property
     *
     * @param target The object data binding is being imposed upon
     * @param propertyName The name of the property being bound to
     * @param value The value of the property being bound
     * @param errors the Spring Errors instance (a org.springframework.validation.BindingResult)
     * @return true if data binding should continue, otherwise return false
     */</span>
    <span class="predefined-type">Boolean</span> beforeBinding(<span class="predefined-type">Object</span> target, <span class="predefined-type">String</span> propertyName, <span class="predefined-type">Object</span> value, <span class="predefined-type">Object</span> errors);

    <span class="comment">/**
     * Called after data binding has been imposed on a property
     *
     * @param target The object data binding is being imposed upon
     * @param propertyName The name of the property that was bound to
     * @param errors the Spring Errors instance (a org.springframework.validation.BindingResult)
     */</span>
    <span class="type">void</span> afterBinding(<span class="predefined-type">Object</span> target, <span class="predefined-type">String</span> propertyName, <span class="predefined-type">Object</span> errors);

    <span class="comment">/**
     * Called after data binding has finished.
     *
     * @param target The object data binding is being imposed upon
     * @param errors the Spring Errors instance (a org.springframework.validation.BindingResult)
     */</span>
    <span class="type">void</span> afterBinding(<span class="predefined-type">Object</span> target, <span class="predefined-type">Object</span> errors);

    <span class="comment">/**
     * Called when an error occurs binding to a property
     * @param error encapsulates information about the binding error
     * @param errors the Spring Errors instance (a org.springframework.validation.BindingResult)
     * @see BindingError
     */</span>
    <span class="type">void</span> bindingError(BindingError error, <span class="predefined-type">Object</span> errors);
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Any bean in the Spring application context which implements that interface will automatically be registered with the data binder.  The <a href="http://docs.grails.org/3.2.11/api/grails/databinding/events/DataBindingListenerAdapter.html">DataBindingListenerAdapter</a> class implements the <code>DataBindingListener</code> interface and provides default implementations for all of the methods in the interface so this class is well suited for subclassing so your listener class only needs to provide implementations for the methods your listener is interested in.</p>
</div>
</div>
<div class="sect3">
<h4 id="_using_the_data_binder_directly">Using The Data Binder Directly</h4>
<div class="paragraph">
<p>There are situations where an application may want to use the data binder directly.  For example, to do binding in a Service on some arbitrary object which is not a domain class.  The following will not work because the <code>properties</code> property is read only.</p>
</div>
<div class="listingblock">
<div class="title">src/main/groovy/bindingdemo/Widget.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> bindingdemo

<span class="type">class</span> <span class="class">Widget</span> {
    <span class="predefined-type">String</span> name
    <span class="predefined-type">Integer</span> size
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">grails-app/services/bindingdemo/WidgetService.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> bindingdemo

<span class="type">class</span> <span class="class">WidgetService</span> {

    <span class="keyword">def</span> <span class="function">updateWidget</span>(Widget widget, <span class="predefined-type">Map</span> data) {
        <span class="comment">// this will throw an exception because</span>
        <span class="comment">// properties is read-only</span>
        widget.properties = data
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>An instance of the data binder is in the Spring application context with a bean name of <code>grailsWebDataBinder</code>.  That bean implements the <a href="http://docs.grails.org/3.2.11/api/grails/databinding/DataBinder.html">DataBinder</a> interface.  The following code demonstrates using the data binder directly.</p>
</div>
<div class="listingblock">
<div class="title">grails-app/services/bindingdmeo/WidgetService</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> bindingdemo

<span class="keyword">import</span> <span class="include">grails.databinding.SimpleMapDataBindingSource</span>

<span class="type">class</span> <span class="class">WidgetService</span> {

    <span class="comment">// this bean will be autowired into the service</span>
    <span class="keyword">def</span> grailsWebDataBinder

    <span class="keyword">def</span> <span class="function">updateWidget</span>(Widget widget, <span class="predefined-type">Map</span> data) {
        grailsWebDataBinder.bind widget, data <span class="keyword">as</span> SimpleMapDataBindingSource
    }

}</code></pre>
</div>
</div>
<div class="paragraph">
<p>See the <a href="http://docs.grails.org/3.2.11/api/grails/databinding/DataBinder.html">DataBinder</a> documentation for more information about overloaded versions
of the <code>bind</code> method.</p>
</div>
</div>
<div class="sect3">
<h4 id="_data_binding_and_security_concerns">Data Binding and Security Concerns</h4>
<div class="paragraph">
<p>When batch updating properties from request parameters you need to be careful not to allow clients to bind malicious data to domain classes and be persisted in the database. You can limit what properties are bound to a given domain class using the subscript operator:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> p = Person.get(<span class="integer">1</span>)

p.properties[<span class="string"><span class="delimiter">'</span><span class="content">firstName</span><span class="delimiter">'</span></span>,<span class="string"><span class="delimiter">'</span><span class="content">lastName</span><span class="delimiter">'</span></span>] = params</code></pre>
</div>
</div>
<div class="paragraph">
<p>In this case only the <code>firstName</code> and <code>lastName</code> properties will be bound.</p>
</div>
<div class="paragraph">
<p>Another way to do this is is to use <a href="theWebLayer.html#commandObjects">Command Objects</a> as the target of data binding instead of domain classes. Alternatively there is also the flexible <a href="../ref/Controllers/bindData.html">bindData</a> method.</p>
</div>
<div class="paragraph">
<p>The <code>bindData</code> method allows the same data binding capability, but to arbitrary objects:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> p = <span class="keyword">new</span> Person()
bindData(p, params)</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>bindData</code> method also lets you exclude certain parameters that you don&#8217;t want updated:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> p = <span class="keyword">new</span> Person()
bindData(p, params, [<span class="key">exclude</span>: <span class="string"><span class="delimiter">'</span><span class="content">dateOfBirth</span><span class="delimiter">'</span></span>])</code></pre>
</div>
</div>
<div class="paragraph">
<p>Or include only certain properties:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> p = <span class="keyword">new</span> Person()
bindData(p, params, [<span class="key">include</span>: [<span class="string"><span class="delimiter">'</span><span class="content">firstName</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">lastName</span><span class="delimiter">'</span></span>]])</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If an empty List is provided as a value for the <code>include</code> parameter then all fields will be subject to binding if they are not explicitly excluded.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <a href="../ref/Constraints/bindable.html">bindable</a> constraint can be used to globally prevent data binding for certain properties.</p>
</div>
</div>


<h2 id="jsonResponses">8.1.6 Responding with JSON</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/jsonResponses.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="sect3">
<h4 id="_using_the_respond_method_to_output_json">Using the respond method to output JSON</h4>
<div class="paragraph">
<p>The <code>respond</code> method is the preferred way to return JSON and integrates with <a href="theWebLayer.html#contentNegotiation">Content Negotiation</a> and <a href="webServices.html#jsonViews">JSON Views</a>.</p>
</div>
<div class="paragraph">
<p>The <code>respond</code> method provides content negotiation strategies to intelligently produce an appropriate response for the given client.</p>
</div>
<div class="paragraph">
<p>For example given the following controller and action:</p>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/example/BookController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> example

<span class="type">class</span> <span class="class">BookController</span> {
    <span class="keyword">def</span> <span class="function">index</span>() {
        respond <span class="predefined-type">Book</span>.list()
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>respond</code> method will take the followings steps:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>If the client <code>Accept</code> header specifies a media type (for example <code>application/json</code>) use that</p>
</li>
<li>
<p>If the file extension of the URI (for example <code>/books.json</code>) includes a format defined in the <code>grails.mime.types</code> property of <code>grails-app/conf/application.yml</code> use the media type defined in the configuration</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>The <code>respond</code> method will then look for an appriopriate <a href="http://docs.grails.org/3.2.11/api/grails/rest/render/Renderer.html">Renderer</a> for the object and the calculated media type from the <a href="http://docs.grails.org/3.2.11/api/grails/rest/render/RendererRegistry.html">RendererRegistry</a>.</p>
</div>
<div class="paragraph">
<p>Grails includes a number of pre-configured <code>Renderer</code> implementations that will produce default representations of JSON responses for the argument passed to <code>respond</code>. For example going to the <code>/book.json</code> URI will produce JSON such as:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="json">[
    {<span class="error">i</span><span class="error">d</span>:<span class="integer">1</span>,<span class="key"><span class="delimiter">&quot;</span><span class="content">title</span><span class="delimiter">&quot;</span></span>:<span class="string"><span class="delimiter">&quot;</span><span class="content">The Stand</span><span class="delimiter">&quot;</span></span>},
    {<span class="error">i</span><span class="error">d</span>:<span class="integer">2</span>,<span class="key"><span class="delimiter">&quot;</span><span class="content">title</span><span class="delimiter">&quot;</span></span>:<span class="string"><span class="delimiter">&quot;</span><span class="content">Shining</span><span class="delimiter">&quot;</span></span>}
]</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_controlling_the_priority_of_media_types">Controlling the Priority of Media Types</h4>
<div class="paragraph">
<p>By default if you define a controller there is no priority in terms of which format is sent back to the client and Grails assumes you wish to serve HTML as a response type.</p>
</div>
<div class="paragraph">
<p>However if your application is primarily an API, then you can specify the priorty using the <code>responseFormats</code> property:</p>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/example/BookController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> example

<span class="type">class</span> <span class="class">BookController</span> {
    <span class="directive">static</span> responseFormats = [<span class="string"><span class="delimiter">'</span><span class="content">json</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">html</span><span class="delimiter">'</span></span>]
    <span class="keyword">def</span> <span class="function">index</span>() {
        respond <span class="predefined-type">Book</span>.list()
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In the above example Grails will respond by default with <code>json</code> if the media type to respond with cannot be calculated from the <code>Accept</code> header or file extension.</p>
</div>
</div>
<div class="sect3">
<h4 id="_using_views_to_output_json_responses">Using Views to Output JSON Responses</h4>
<div class="paragraph">
<p>If you define a view (either a GSP or a <a href="webServices.html#jsonViews">JSON View</a>) then Grails will render the view when using the <code>respond</code> method by calculating a model from the argument passed to <code>respond</code>.</p>
</div>
<div class="paragraph">
<p>For example, in the previous listing, if you were to define <code>grails-app/views/index.gson</code> and <code>grails-app/views/index.gsp</code> views, these would be used if the client requested <code>application/json</code> or <code>text/html</code> media types respectively. Thus allowing you to define a single backend capible of serving responses to a web browser or representing your application&#8217;s API.</p>
</div>
<div class="paragraph">
<p>When rendering the view, Grails will calculate a model to pass to the view based on the type of the value passed to the <code>respond</code> method.</p>
</div>
<div class="paragraph">
<p>The following table summarizes this convention:</p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Example</th>
<th class="tableblock halign-left valign-top">Argument Type</th>
<th class="tableblock halign-left valign-top">Calculated Model Variable</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>respond Book.list()</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>java.util.List</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>bookList</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>respond( [] )</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>java.util.List</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>emptyList</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>respond Book.get(1)</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>example.Book</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>book</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>respond( [1,2] )</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>java.util.List</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>integerList</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>respond( [1,2] as Set )</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>java.util.Set</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>integerSet</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>respond( [1,2] as Integer[] )</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Integer[]</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>integerArray</code></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>Using this convention you can reference the argument passed to <code>respond</code> from within your view:</p>
</div>
<div class="listingblock">
<div class="title">grails-app/views/book/index.gson</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="annotation">@Field</span> <span class="predefined-type">List</span>&lt;<span class="predefined-type">Book</span>&gt; bookList = <span class="type">[]</span>

json bookList, { <span class="predefined-type">Book</span> book -&gt;
    title book.title
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>You will notice that if <code>Book.list()</code> returns an empty list then the model variable name is translated to <code>emptyList</code>. This is by design and you should provide a default value in the view if no model variable is specified, such as the <code>List</code> in the example above:</p>
</div>
<div class="listingblock">
<div class="title">grails-app/views/book/index.gson</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="comment">// defaults to an empty list</span>
<span class="annotation">@Field</span> <span class="predefined-type">List</span>&lt;<span class="predefined-type">Book</span>&gt; bookList = <span class="type">[]</span>
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>There are cases where you may wish to be more explicit and control the name of the model variable. For example if you have a domain inheritance hierarchy where a call to <code>list()</code> my return different child classes relying on automatic calculation may not be reliable.</p>
</div>
<div class="paragraph">
<p>In this case you should pass the model directly using <code>respond</code> and a map argument:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">respond <span class="key">bookList</span>: <span class="predefined-type">Book</span>.list()</code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
When responding with any kind of mixed argument types in a collection, always use an explicit model name.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>If you simply wish to augment the calculated model then you can do so by passing a <code>model</code> argument:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">respond <span class="predefined-type">Book</span>.list(), [<span class="key">model</span>: [<span class="key">bookCount</span>: <span class="predefined-type">Book</span>.count()]]</code></pre>
</div>
</div>
<div class="paragraph">
<p>The above example will produce a model like <code>[bookList:books, bookCount:totalBooks]</code>, where the calculated model is combined with the model passed in the <code>model</code> argument.</p>
</div>
</div>
<div class="sect3">
<h4 id="_using_the_render_method_to_output_json">Using the render method to output JSON</h4>
<div class="paragraph">
<p>The <code>render</code> method can also be used to output JSON, but should only be used for simple cases that don&#8217;t warrant the creation of a JSON view:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">list</span>() {

    <span class="keyword">def</span> results = <span class="predefined-type">Book</span>.list()

    render(<span class="key">contentType</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">application/json</span><span class="delimiter">&quot;</span></span>) {
        books(results) { <span class="predefined-type">Book</span> b -&gt;
            title b.title
        }
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In this case the result would be something along the lines of:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="json">[
    {<span class="key"><span class="delimiter">&quot;</span><span class="content">title</span><span class="delimiter">&quot;</span></span>:<span class="string"><span class="delimiter">&quot;</span><span class="content">The Stand</span><span class="delimiter">&quot;</span></span>},
    {<span class="key"><span class="delimiter">&quot;</span><span class="content">title</span><span class="delimiter">&quot;</span></span>:<span class="string"><span class="delimiter">&quot;</span><span class="content">Shining</span><span class="delimiter">&quot;</span></span>}
]</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
This technique for rendering JSON may be ok for very simple responses, but in general you should favour the use of <a href="webServices.html#jsonViews">JSON Views</a> and use the view layer rather than embedding logic in your application.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The same dangers with naming conflicts described above for XML also apply to JSON building.</p>
</div>
</div>

<a name="7.1.8 More on JSONBuilder"><!-- Legacy link --></a>
<h2 id="moreOnJSONBuilder">8.1.7 More on JSONBuilder</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/moreOnJSONBuilder.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="paragraph">
<p>The previous section on XML and JSON responses covered simplistic examples of rendering XML and JSON responses. Whilst the XML builder used by Grails is the standard <a href="http://groovy-lang.org/processing-xml.html#_xmlparser_and_xmlslurper">XmlSlurper</a> found in Groovy.</p>
</div>
<div class="paragraph">
<p>For JSON, since Grails 3.1, Grails uses Groovy&#8217;s <a href="http://docs.groovy-lang.org/latest/html/documentation/core-domain-specific-languages.html#_streamingjsonbuilder">StreamingJsonBuilder</a> by default and you can refer to the <a href="http://docs.groovy-lang.org/latest/html/documentation/core-domain-specific-languages.html#_streamingjsonbuilder">Groovy documentation</a> and <a href="http://docs.groovy-lang.org/latest/html/gapi/groovy/json/StreamingJsonBuilder.html">StreamingJsonBuilder</a> API documentation on how to use it.</p>
</div>


<h2 id="xmlResponses">8.1.8 Responding with XML</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/xmlResponses.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>




<a name="7.1.9 Uploading Files"><!-- Legacy link --></a>
<h2 id="uploadingFiles">8.1.9 Uploading Files</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/uploadingFiles.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="sect3">
<h4 id="_programmatic_file_uploads">Programmatic File Uploads</h4>
<div class="paragraph">
<p>Grails supports file uploads using Spring&#8217;s <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/MultipartHttpServletRequest.html">MultipartHttpServletRequest</a> interface. The first step for file uploading is to create a multipart form like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml">Upload Form: <span class="tag">&lt;br</span> <span class="tag">/&gt;</span>
    <span class="tag">&lt;g:uploadForm</span> <span class="attribute-name">action</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">upload</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
        <span class="tag">&lt;input</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">file</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">myFile</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
        <span class="tag">&lt;input</span> <span class="attribute-name">type</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">submit</span><span class="delimiter">&quot;</span></span> <span class="tag">/&gt;</span>
    <span class="tag">&lt;/g:uploadForm&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>uploadForm</code> tag conveniently adds the <code>enctype="multipart/form-data"</code> attribute to the standard <code>&lt;g:form&gt;</code> tag.</p>
</div>
<div class="paragraph">
<p>There are then a number of ways to handle the file upload. One is to work with the Spring <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/MultipartFile.html">MultipartFile</a> instance directly:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> <span class="function">upload</span>() {
    <span class="keyword">def</span> f = request.getFile(<span class="string"><span class="delimiter">'</span><span class="content">myFile</span><span class="delimiter">'</span></span>)
    <span class="keyword">if</span> (f.empty) {
        flash.message = <span class="string"><span class="delimiter">'</span><span class="content">file cannot be empty</span><span class="delimiter">'</span></span>
        render(<span class="key">view</span>: <span class="string"><span class="delimiter">'</span><span class="content">uploadForm</span><span class="delimiter">'</span></span>)
        <span class="keyword">return</span>
    }

    f.transferTo(<span class="keyword">new</span> <span class="predefined-type">File</span>(<span class="string"><span class="delimiter">'</span><span class="content">/some/local/dir/myfile.txt</span><span class="delimiter">'</span></span>))
    response.sendError(<span class="integer">200</span>, <span class="string"><span class="delimiter">'</span><span class="content">Done</span><span class="delimiter">'</span></span>)
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This is convenient for doing transfers to other destinations and manipulating the file directly as you can obtain an <code>InputStream</code> and so on with the <a href="https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/MultipartFile.html">MultipartFile</a> interface.</p>
</div>
</div>
<div class="sect3">
<h4 id="_file_uploads_through_data_binding">File Uploads through Data Binding</h4>
<div class="paragraph">
<p>File uploads can also be performed using data binding. Consider this <code>Image</code> domain class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">Image</span> {
    <span class="type">byte</span><span class="type">[]</span> myFile

    <span class="directive">static</span> constraints = {
        <span class="comment">// Limit upload file size to 2MB</span>
        myFile <span class="key">maxSize</span>: <span class="integer">1024</span> * <span class="integer">1024</span> * <span class="integer">2</span>
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you create an image using the <code>params</code> object in the constructor as in the example below, Grails will automatically bind the file&#8217;s contents as a <code>byte[]</code> to the <code>myFile</code> property:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> img = <span class="keyword">new</span> <span class="predefined-type">Image</span>(params)</code></pre>
</div>
</div>
<div class="paragraph">
<p>It&#8217;s important that you set the <a href="../ref/Constraints/size.html">size</a> or <a href="../ref/Constraints/maxSize.html">maxSize</a> constraints, otherwise your database may be created with a small column size that can&#8217;t handle reasonably sized files. For example, both H2 and MySQL default to a blob size of 255 bytes for <code>byte[]</code> properties.</p>
</div>
<div class="paragraph">
<p>It is also possible to set the contents of the file as a string by changing the type of the <code>myFile</code> property on the image to a String type:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">Image</span> {
   <span class="predefined-type">String</span> myFile
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_increase_upload_max_file_size">Increase Upload Max File Size</h4>
<div class="paragraph">
<p>Grails default size for file uploads is 128000 (~128KB). When this limit is exceeded you&#8217;ll see the following exception:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase<span class="error">$</span><span class="exception">SizeLimitExceededException</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>You can configure the limit in your <code>application.yml</code> as follows:</p>
</div>
<div class="listingblock">
<div class="title">grails-app/conf/application.yml</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="yml"><span class="key">grails</span>:
    <span class="key">controllers</span>:
        <span class="key">upload</span>:
            <span class="key">maxFileSize</span>: <span class="string"><span class="content">2000000</span></span>
            <span class="key">maxRequestSize</span>: <span class="string"><span class="content">2000000</span></span></code></pre>
</div>
</div>
<div class="paragraph">
<p><code>maxFileSize</code> = The maximum size allowed for uploaded files.</p>
</div>
<div class="paragraph">
<p><code>maxRequestSize</code> =  The maximum size allowed for multipart/form-data requests.</p>
</div>
<div class="paragraph">
<p>You should keep in mind <a href="https://www.owasp.org/index.php/Unrestricted_File_Upload">OWASP recommendations - Unrestricted File Upload</a></p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Limit the file size to a maximum value in order to prevent denial of service attacks.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>These limits exist to prevent DoS attacks and to enforce overall application performance</p>
</div>
</div>

<a name="7.1.10 Command Objects"><!-- Legacy link --></a>
<h2 id="commandObjects">8.1.10 Command Objects</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/commandObjects.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="paragraph">
<p>Grails controllers support the concept of command objects. A command object is a class that is used in conjunction with <a href="theWebLayer.html#dataBinding">data binding</a>, usually to allow validation of data that may not fit into an existing domain class.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
A class is only considered to be a command object when it is used as a parameter of an action.
</td>
</tr>
</table>
</div>
<div class="sect3">
<h4 id="_declaring_command_objects">Declaring Command Objects</h4>
<div class="paragraph">
<p>Command object classes are defined just like any other class.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">LoginCommand</span> <span class="directive">implements</span> grails.validation.Validateable {
    <span class="predefined-type">String</span> username
    <span class="predefined-type">String</span> password

    <span class="directive">static</span> constraints = {
        username(<span class="key">blank</span>: <span class="predefined-constant">false</span>, <span class="key">minSize</span>: <span class="integer">6</span>)
        password(<span class="key">blank</span>: <span class="predefined-constant">false</span>, <span class="key">minSize</span>: <span class="integer">6</span>)
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In this example, the command object class implements the <code>Validateable</code> trait. The <code>Validateable</code> trait allows the definition of <a href="validation.html#constraints">Constraints</a> just like in <a href="GORM.html">domain classes</a>. If the command object is defined in the same source file as the controller that is using it, Grails will automatically make it <code>Validateable</code>. It is not required that command object classes be validateable.</p>
</div>
<div class="paragraph">
<p>By default, all <code>Validateable</code> object properties which are not instances of <code>java.util.Collection</code> or <code>java.util.Map</code> are <code>nullable: false</code>.  Instances of <code>java.util.Collection</code> and <code>java.util.Map</code> default to <code>nullable: true</code>.  If you want a <code>Validateable</code> that has <code>nullable: true</code> properties by default, you can specify this by defining a <code>defaultNullable</code> method in the class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">AuthorSearchCommand</span> <span class="directive">implements</span> grails.validation.Validateable {
    <span class="predefined-type">String</span>  name
    <span class="predefined-type">Integer</span> age

    <span class="directive">static</span> <span class="type">boolean</span> defaultNullable() {
        <span class="predefined-constant">true</span>
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In this example, both <code>name</code> and <code>age</code> will allow null values during validation.</p>
</div>
</div>
<div class="sect3">
<h4 id="_using_command_objects">Using Command Objects</h4>
<div class="paragraph">
<p>To use command objects, controller actions may optionally specify any number of command object parameters. The parameter types must be supplied so that Grails knows what objects to create and initialize.</p>
</div>
<div class="paragraph">
<p>Before the controller action is executed Grails will automatically create an instance of the command object class and populate its properties by binding the request parameters.  If the command object class is marked with <code>Validateable</code> then the command object will be validated. For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">LoginController</span> {

    <span class="keyword">def</span> <span class="function">login</span>(LoginCommand cmd) {
        <span class="keyword">if</span> (cmd.hasErrors()) {
            redirect(<span class="key">action</span>: <span class="string"><span class="delimiter">'</span><span class="content">loginForm</span><span class="delimiter">'</span></span>)
            <span class="keyword">return</span>
        }

        <span class="comment">// work with the command object data</span>
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If the command object&#8217;s type is that of a domain class and there is an <code>id</code> request parameter then instead of invoking the domain class constructor to create a new instance a call will be made to the static <code>get</code> method on the domain class and the value of the <code>id</code> parameter will be passed as an argument.</p>
</div>
<div class="paragraph">
<p>Whatever is returned from that call to <code>get</code> is what will be passed into the controller action.  This means that if there is an <code>id</code> request parameter and no corresponding record is found in the database then the value of the command object will be <code>null</code>.  If an error occurs retrieving the instance from the database then <code>null</code> will be passed as an argument to the controller action and an error will be added the controller&#8217;s <code>errors</code> property.</p>
</div>
<div class="paragraph">
<p>If the command object&#8217;s type is a domain class and there is no <code>id</code> request parameter or there is an <code>id</code> request parameter and its value is empty then <code>null</code> will be passed into the controller action unless the HTTP request method is "POST", in which case a new instance of the domain class will be created by invoking the domain class constructor.  For all of the cases where the domain class instance is non-null, data binding is only performed if the HTTP request method is "POST", "PUT" or "PATCH".</p>
</div>
</div>
<div class="sect3">
<h4 id="_command_objects_and_request_parameter_names">Command Objects And Request Parameter Names</h4>
<div class="paragraph">
<p>Normally request parameter names will be mapped directly to property names in the command object.  Nested parameter names may be used to bind down the object graph in an intuitive way.</p>
</div>
<div class="paragraph">
<p>In the example below a request parameter named <code>name</code> will be bound to the <code>name</code> property of the <code>Person</code> instance and a request parameter named <code>address.city</code> will be bound to the <code>city</code> property of the <code>address</code> property in the <code>Person</code>.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">StoreController</span> {
    <span class="keyword">def</span> <span class="function">buy</span>(Person buyer) {
        <span class="comment">// ...</span>
    }
}

<span class="type">class</span> <span class="class">Person</span> {
    <span class="predefined-type">String</span> name
    Address address
}

<span class="type">class</span> <span class="class">Address</span> {
    <span class="predefined-type">String</span> city
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>A problem may arise if a controller action accepts multiple command objects which happen to contain the same property name.  Consider the following example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">StoreController</span> {
    <span class="keyword">def</span> <span class="function">buy</span>(Person buyer, Product product) {
        <span class="comment">// ...</span>
    }
}

<span class="type">class</span> <span class="class">Person</span> {
    <span class="predefined-type">String</span> name
    Address address
}

<span class="type">class</span> <span class="class">Address</span> {
    <span class="predefined-type">String</span> city
}

<span class="type">class</span> <span class="class">Product</span> {
    <span class="predefined-type">String</span> name
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If there is a request parameter named <code>name</code> it isn&#8217;t clear if that should represent the name of the <code>Product</code> or the name of the <code>Person</code>.  Another version of the problem can come up if a controller action accepts 2 command objects of the same type as shown below.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">StoreController</span> {
    <span class="keyword">def</span> <span class="function">buy</span>(Person buyer, Person seller, Product product) {
        <span class="comment">// ...</span>
    }
}

<span class="type">class</span> <span class="class">Person</span> {
    <span class="predefined-type">String</span> name
    Address address
}

<span class="type">class</span> <span class="class">Address</span> {
    <span class="predefined-type">String</span> city
}

<span class="type">class</span> <span class="class">Product</span> {
    <span class="predefined-type">String</span> name
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>To help deal with this the framework imposes special rules for mapping parameter names to command object types.  The command object data binding will treat all parameters that begin with the controller action parameter name as belonging to the corresponding command object.</p>
</div>
<div class="paragraph">
<p>For example, the <code>product.name</code> request parameter will be bound to the <code>name</code> property in the <code>product</code> argument, the <code>buyer.name</code> request parameter will be bound to the <code>name</code> property in the <code>buyer</code> argument the <code>seller.address.city</code> request parameter will be bound to the <code>city</code> property of the <code>address</code> property of the <code>seller</code> argument, etc&#8230;&#8203;</p>
</div>
</div>
<div class="sect3">
<h4 id="_command_objects_and_dependency_injection">Command Objects and Dependency Injection</h4>
<div class="paragraph">
<p>Command objects can participate in dependency injection. This is useful if your command object has some custom validation logic which uses a Grails <a href="services.html">service</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">LoginCommand</span> <span class="directive">implements</span> grails.validation.Validateable {

    <span class="keyword">def</span> loginService

    <span class="predefined-type">String</span> username
    <span class="predefined-type">String</span> password

    <span class="directive">static</span> constraints = {
        username <span class="key">validator</span>: { val, obj -&gt;
            obj.loginService.canLogin(obj.username, obj.password)
        }
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In this example the command object interacts with the <code>loginService</code> bean which is injected by name from the Spring <code>ApplicationContext</code>.</p>
</div>
</div>
<div class="sect3">
<h4 id="_binding_the_request_body_to_command_objects">Binding The Request Body To Command Objects</h4>
<div class="paragraph">
<p>When a request is made to a controller action which accepts a command object and the request contains a body, Grails will attempt to parse the body of the request based on the request content type and use the body to do data binding on the command object.  See the following example.</p>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/bindingdemo/DemoController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> bindingdemo

<span class="type">class</span> <span class="class">DemoController</span> {

    <span class="keyword">def</span> <span class="function">createWidget</span>(Widget w) {
        render <span class="string"><span class="delimiter">&quot;</span><span class="content">Name: </span><span class="inline"><span class="inline-delimiter">${</span>w?.name<span class="inline-delimiter">}</span></span><span class="content">, Size: </span><span class="inline"><span class="inline-delimiter">${</span>w?.size<span class="inline-delimiter">}</span></span><span class="delimiter">&quot;</span></span>
    }
}

<span class="type">class</span> <span class="class">Widget</span> {
    <span class="predefined-type">String</span> name
    <span class="predefined-type">Integer</span> size
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="bash">$ curl -H &quot;Content-Type: application/json&quot; -d '{&quot;name&quot;:&quot;Some Widget&quot;,&quot;42&quot;}'[size] localhost:8080/demo/createWidget
 Name: Some Widget, Size: 42

$ curl -H &quot;Content-Type: application/xml&quot; -d '&lt;widget&gt;&lt;name&gt;Some Other Widget&lt;/name&gt;&lt;size&gt;2112&lt;/size&gt;&lt;/widget&gt;' localhost:8080/bodybind/demo/createWidget
 Name: Some Other Widget, Size: 2112</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The request body will not be parsed under the following conditions:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The request method is GET</p>
</li>
<li>
<p>The request method is DELETE</p>
</li>
<li>
<p>The content length is 0</p>
</li>
</ul>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Note that the body of the request is being parsed to make that work.  Any attempt to read the body of the request after that will fail since the corresponding input stream will be empty.  The controller action can either use a command object or it can parse the body of the request on its own (either directly, or by referring to something like request.JSON), but cannot do both.</p>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/bindingdemo/DemoController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> bindingdemo

<span class="type">class</span> <span class="class">DemoController</span> {

    <span class="keyword">def</span> <span class="function">createWidget</span>(Widget w) {
        <span class="comment">// this will fail because it requires reading the body,</span>
        <span class="comment">// which has already been read.</span>
        <span class="keyword">def</span> json = request.JSON

        <span class="comment">// ...</span>

    }
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_working_with_lists_of_command_objects">Working with Lists of Command Objects</h4>
<div class="paragraph">
<p>A common use case for command objects is a Command Object that contains a collection of another:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="type">class</span> <span class="class">DemoController</span> {

    <span class="keyword">def</span> <span class="function">createAuthor</span>(AuthorCommand command) {
        <span class="comment">// ...</span>

    }

    <span class="type">class</span> <span class="class">AuthorCommand</span> {
        <span class="predefined-type">String</span> fullName
        <span class="predefined-type">List</span>&lt;BookCommand&gt; books
    }

    <span class="type">class</span> <span class="class">BookCommand</span> {
        <span class="predefined-type">String</span> title
        <span class="predefined-type">String</span> isbn
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>On this example, we want to create an Author with multiple Books.</p>
</div>
<div class="paragraph">
<p>In order to make this work from the UI layer, you can do the following in your GSP:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:form</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">submit-author-books</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">controller</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">demo</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">action</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">createAuthor</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
    <span class="tag">&lt;g:fieldValue</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">fullName</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
    <span class="tag">&lt;ul&gt;</span>
        <span class="tag">&lt;li&gt;</span>
            <span class="tag">&lt;g:fieldValue</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[0].title</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
            <span class="tag">&lt;g:fieldValue</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[0].isbn</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
        <span class="tag">&lt;/li&gt;</span>

        <span class="tag">&lt;li&gt;</span>
            <span class="tag">&lt;g:fieldValue</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[1].title</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
            <span class="tag">&lt;g:fieldValue</span> <span class="attribute-name">name</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">books[1].isbn</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">value</span>=<span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span><span class="tag">/&gt;</span>
        <span class="tag">&lt;/li&gt;</span>
    <span class="tag">&lt;/ul&gt;</span>
<span class="tag">&lt;/g:form&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>There is also support for JSON, so you can submit the following with correct databinding</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="json">{
    <span class="key"><span class="delimiter">&quot;</span><span class="content">fullName</span><span class="delimiter">&quot;</span></span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">Graeme Rocher</span><span class="delimiter">&quot;</span></span>,
    <span class="key"><span class="delimiter">&quot;</span><span class="content">books</span><span class="delimiter">&quot;</span></span>: [{
        <span class="key"><span class="delimiter">&quot;</span><span class="content">title</span><span class="delimiter">&quot;</span></span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">The Definitive Guide to Grails</span><span class="delimiter">&quot;</span></span>,
        <span class="key"><span class="delimiter">&quot;</span><span class="content">isbn</span><span class="delimiter">&quot;</span></span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">1111-343455-1111</span><span class="delimiter">&quot;</span></span>
    }, {
        <span class="key"><span class="delimiter">&quot;</span><span class="content">title</span><span class="delimiter">&quot;</span></span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">The Definitive Guide to Grails 2</span><span class="delimiter">&quot;</span></span>,
        <span class="key"><span class="delimiter">&quot;</span><span class="content">isbn</span><span class="delimiter">&quot;</span></span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">1111-343455-1112</span><span class="delimiter">&quot;</span></span>
    }],
}</code></pre>
</div>
</div>
</div>

<a name="7.1.11 Handling Duplicate Form Submissions"><!-- Legacy link --></a>
<h2 id="formtokens">8.1.11 Handling Duplicate Form Submissions</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/formtokens.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="paragraph">
<p>Grails has built-in support for handling duplicate form submissions using the "Synchronizer Token Pattern". To get started you define a token on the <a href="../ref/Tags/form.html">form</a> tag:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:form</span> <span class="attribute-name">useToken</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">true</span><span class="delimiter">&quot;</span></span> <span class="attribute-name">...</span><span class="tag">&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Then in your controller code you can use the <a href="../ref/Controllers/withForm.html">withForm</a> method to handle valid and invalid requests:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy">withForm {
   <span class="comment">// good request</span>
}.invalidToken {
   <span class="comment">// bad request</span>
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you only provide the <a href="../ref/Controllers/withForm.html">withForm</a> method and not the chained <code>invalidToken</code> method then by default Grails will store the invalid token in a <code>flash.invalidToken</code> variable and redirect the request back to the original page. This can then be checked in the view:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="xml"><span class="tag">&lt;g:if</span> <span class="attribute-name">test</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">${flash.invalidToken}</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
  Don't click the button twice!
<span class="tag">&lt;/g:if&gt;</span></code></pre>
</div>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
The <a href="../ref/Controllers/withForm.html">withForm</a> tag makes use of the <a href="../ref/Controllers/session.html">session</a> and hence requires session affinity or clustered sessions if used in a cluster.
</td>
</tr>
</table>
</div>

<a name="7.1.12 Simple Type Converters"><!-- Legacy link --></a>
<h2 id="typeConverters">8.1.12 Simple Type Converters</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/typeConverters.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="sect2">
<h3 id="_type_conversion_methods">Type Conversion Methods</h3>
<div class="paragraph">
<p>If you prefer to avoid the overhead of <a href="theWebLayer.html#dataBinding">data binding</a> and simply want to convert incoming parameters (typically Strings) into another more appropriate type the <a href="../ref/Controllers/params.html">params</a> object has a number of convenience methods for each type:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> total = params.int(<span class="string"><span class="delimiter">'</span><span class="content">total</span><span class="delimiter">'</span></span>)</code></pre>
</div>
</div>
<div class="paragraph">
<p>The above example uses the <code>int</code> method, and there are also methods for <code>boolean</code>, <code>long</code>, <code>char</code>, <code>short</code> and so on. Each of these methods is null-safe and safe from any parsing errors, so you don&#8217;t have to perform any additional checks on the parameters.</p>
</div>
<div class="paragraph">
<p>Each of the conversion methods allows a default value to be passed as an optional second argument.  The default value will be returned if a corresponding entry cannot be found in the map or if an error occurs during the conversion.  Example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">def</span> total = params.int(<span class="string"><span class="delimiter">'</span><span class="content">total</span><span class="delimiter">'</span></span>, <span class="integer">42</span>)</code></pre>
</div>
</div>
<div class="paragraph">
<p>These same type conversion methods are also available on the <code>attrs</code> parameter of GSP tags.</p>
</div>
</div>
<div class="sect2">
<h3 id="_handling_multi_parameters">Handling Multi Parameters</h3>
<div class="paragraph">
<p>A common use case is dealing with multiple request parameters of the same name. For example you could get a query string such as <code>?name=Bob&amp;name=Judy</code>.</p>
</div>
<div class="paragraph">
<p>In this case dealing with one parameter and dealing with many has different semantics since Groovy&#8217;s iteration mechanics for <code>String</code> iterate over each character. To avoid this problem the <a href="../ref/Controllers/params.html">params</a> object provides a <code>list</code> method that always returns a list:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">for</span> (name <span class="keyword">in</span> params.list(<span class="string"><span class="delimiter">'</span><span class="content">name</span><span class="delimiter">'</span></span>)) {
    println name
}</code></pre>
</div>
</div>
</div>


<h2 id="controllerExceptionHandling">8.1.13 Declarative Controller Exception Handling</h2>

<div class='contribute-btn'>
    <button type='button' class='btn btn-default' onclick='window.location.href="https://github.com/grails/grails-doc/edit/3.2.x/src/en/guide/theWebLayer/controllers/controllerExceptionHandling.adoc"'>
        <i class='fa fa-pencil-square-o'></i> Improve this doc
    </button>
</div>


<div class="paragraph">
<p>Grails controllers support a simple mechanism for declarative exception handling.  If a controller declares a method that accepts a single argument and the argument type is <code>java.lang.Exception</code> or some subclass of <code>java.lang.Exception</code>, that method will be invoked any time an action in that controller throws an exception of that type.  See the following example.</p>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/demo/DemoController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> demo

<span class="type">class</span> <span class="class">DemoController</span> {

    <span class="keyword">def</span> <span class="function">someAction</span>() {
        <span class="comment">// do some work</span>
    }

    <span class="keyword">def</span> <span class="function">handleSQLException</span>(<span class="exception">SQLException</span> e) {
        render <span class="string"><span class="delimiter">'</span><span class="content">A SQLException Was Handled</span><span class="delimiter">'</span></span>
    }

    <span class="keyword">def</span> <span class="function">handleBatchUpdateException</span>(<span class="exception">BatchUpdateException</span> e) {
        redirect <span class="key">controller</span>: <span class="string"><span class="delimiter">'</span><span class="content">logging</span><span class="delimiter">'</span></span>, <span class="key">action</span>: <span class="string"><span class="delimiter">'</span><span class="content">batchProblem</span><span class="delimiter">'</span></span>
    }

    <span class="keyword">def</span> <span class="function">handleNumberFormatException</span>(<span class="exception">NumberFormatException</span> nfe) {
        [<span class="key">problemDescription</span>: <span class="string"><span class="delimiter">'</span><span class="content">A Number Was Invalid</span><span class="delimiter">'</span></span>]
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>That controller will behave as if it were written something like this&#8230;&#8203;</p>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/demo/DemoController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> demo

<span class="type">class</span> <span class="class">DemoController</span> {

    <span class="keyword">def</span> <span class="function">someAction</span>() {
        <span class="keyword">try</span> {
            <span class="comment">// do some work</span>
        } <span class="keyword">catch</span> (<span class="exception">BatchUpdateException</span> e) {
            <span class="keyword">return</span> handleBatchUpdateException(e)
        } <span class="keyword">catch</span> (<span class="exception">SQLException</span> e) {
            <span class="keyword">return</span> handleSQLException(e)
        } <span class="keyword">catch</span> (<span class="exception">NumberFormatException</span> e) {
            <span class="keyword">return</span> handleNumberFormatException(e)
        }
    }

    <span class="keyword">def</span> <span class="function">handleSQLException</span>(<span class="exception">SQLException</span> e) {
        render <span class="string"><span class="delimiter">'</span><span class="content">A SQLException Was Handled</span><span class="delimiter">'</span></span>
    }

    <span class="keyword">def</span> <span class="function">handleBatchUpdateException</span>(<span class="exception">BatchUpdateException</span> e) {
        redirect <span class="key">controller</span>: <span class="string"><span class="delimiter">'</span><span class="content">logging</span><span class="delimiter">'</span></span>, <span class="key">action</span>: <span class="string"><span class="delimiter">'</span><span class="content">batchProblem</span><span class="delimiter">'</span></span>
    }

    <span class="keyword">def</span> <span class="function">handleNumberFormatException</span>(<span class="exception">NumberFormatException</span> nfe) {
        [<span class="key">problemDescription</span>: <span class="string"><span class="delimiter">'</span><span class="content">A Number Was Invalid</span><span class="delimiter">'</span></span>]
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The exception handler method names can be any valid method name.  The name is not what makes the method an exception handler, the <code>Exception</code> argument type is the important part.</p>
</div>
<div class="paragraph">
<p>The exception handler methods can do anything that a controller action can do including invoking <code>render</code>, <code>redirect</code>, returning a model, etc.</p>
</div>
<div class="paragraph">
<p>One way to share exception handler methods across multiple controllers is to use inheritance.  Exception handler methods are inherited into subclasses so an application could define the exception handlers in an abstract class that multiple controllers extend from.  Another way to share exception handler methods across multiple controllers is to use a trait, as shown below&#8230;&#8203;</p>
</div>
<div class="listingblock">
<div class="title">src/main/groovy/com/demo/DatabaseExceptionHandler.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

trait DatabaseExceptionHandler {
    <span class="keyword">def</span> <span class="function">handleSQLException</span>(<span class="exception">SQLException</span> e) {
        <span class="comment">// handle SQLException</span>
    }

    <span class="keyword">def</span> <span class="function">handleBatchUpdateException</span>(<span class="exception">BatchUpdateException</span> e) {
        <span class="comment">// handle BatchUpdateException</span>
    }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">grails-app/controllers/com/demo/DemoController.groovy</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="groovy"><span class="keyword">package</span> com.demo

<span class="type">class</span> <span class="class">DemoController</span> <span class="directive">implements</span> DatabaseExceptionHandler {

    <span class="comment">// all of the exception handler methods defined</span>
    <span class="comment">// in DatabaseExceptionHandler will be added to</span>
    <span class="comment">// this class at compile time</span>
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Exception handler methods must be present at compile time.  Specifically, exception handler methods which are runtime metaprogrammed onto a controller class are not supported.</p>
</div>


                <div style="clear:both;margin-top:15px;"></div>
                
                    <div class="toc-item prev-left"><a href="../../guide/GORM.html">&lt;&lt; <strong>7</strong><span>Object Relational Mapping (GORM)</span></a></div>
                
                    <div class="toc-item next-right"><a href="../../guide/traits.html"><strong>9</strong><span>Traits</span> >></a></div>
                
                <div style="clear:both"></div>
            </div>
        </td>
        <td id="col2">
            <div class="local clearfix">
                <div class="local-title">
                    <a href="../../guide/index.html" target="mainFrame">Quick Reference</a>
                    <span class="toggle">(<a href="#" onclick="localToggle(); return false;">hide</a>)</span>
                </div>
                <div class="menu">
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Command Line</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Command%20Line/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/bug-report.html">bug-report</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/clean.html">clean</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/compile.html">compile</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/console.html">console</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-app.html">create-app</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-command.html">create-command</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-controller.html">create-controller</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-domain-class.html">create-domain-class</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-functional-test.html">create-functional-test</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-hibernate-cfg-xml.html">create-hibernate-cfg-xml</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-integration-test.html">create-integration-test</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-interceptor.html">create-interceptor</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-plugin.html">create-plugin</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-profile.html">create-profile</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-script.html">create-script</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-service.html">create-service</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-taglib.html">create-taglib</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/create-unit-test.html">create-unit-test</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/dependency-report.html">dependency-report</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/docs.html">docs</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/generate-all.html">generate-all</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/generate-controller.html">generate-controller</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/generate-views.html">generate-views</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/help.html">help</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/install-templates.html">install-templates</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/list-plugins.html">list-plugins</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/list-profiles.html">list-profiles</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/package-plugin.html">package-plugin</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/package.html">package</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/plugin-info.html">plugin-info</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/profile-info.html">profile-info</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/run-app.html">run-app</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/run-command.html">run-command</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/run-script.html">run-script</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/schema-export.html">schema-export</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/shell.html">shell</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/stats.html">stats</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/stop-app.html">stop-app</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/test-app.html">test-app</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Command%20Line/war.html">war</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Constraints</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Constraints/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Constraints/attributes.html">attributes</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/bindable.html">bindable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/blank.html">blank</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/creditCard.html">creditCard</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/email.html">email</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/inList.html">inList</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/matches.html">matches</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/max.html">max</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/maxSize.html">maxSize</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/min.html">min</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/minSize.html">minSize</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/notEqual.html">notEqual</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/nullable.html">nullable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/range.html">range</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/scale.html">scale</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/size.html">size</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/unique.html">unique</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/url.html">url</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/validator.html">validator</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Constraints/widget.html">widget</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Controllers</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Controllers/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Controllers/actionName.html">actionName</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/allowedMethods.html">allowedMethods</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/bindData.html">bindData</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/chain.html">chain</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/controllerName.html">controllerName</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/defaultAction.html">defaultAction</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/errors.html">errors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/flash.html">flash</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/forward.html">forward</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/grailsApplication.html">grailsApplication</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/hasErrors.html">hasErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/namespace.html">namespace</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/params.html">params</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/redirect.html">redirect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/render.html">render</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/request.html">request</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/respond.html">respond</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/response.html">response</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/responseFormats.html">responseFormats</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/scope.html">scope</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/servletContext.html">servletContext</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/session.html">session</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/withForm.html">withForm</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Controllers/withFormat.html">withFormat</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Database Mapping</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/autoImport.html">autoImport</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/autoTimestamp.html">autoTimestamp</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/batchSize.html">batchSize</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/cache.html">cache</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/cascade.html">cascade</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/column.html">column</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/comment.html">comment</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/discriminator.html">discriminator</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/dynamicInsert.html">dynamicInsert</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/dynamicUpdate.html">dynamicUpdate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/fetch.html">fetch</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/id.html">id</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/ignoreNotFound.html">ignoreNotFound</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/indexColumn.html">indexColumn</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/insertable.html">insertable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/joinTable.html">joinTable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/lazy.html">lazy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/order.html">order</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/sort.html">sort</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/table.html">table</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/type.html">type</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/updateable.html">updateable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Database%20Mapping/version.html">version</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Domain Classes</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/addTo.html">addTo</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/attach.html">attach</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/belongsTo.html">belongsTo</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/clearErrors.html">clearErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/constraints.html">constraints</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/count.html">count</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/countBy.html">countBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/createCriteria.html">createCriteria</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/delete.html">delete</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/discard.html">discard</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/embedded.html">embedded</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/errors.html">errors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/executeQuery.html">executeQuery</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/executeUpdate.html">executeUpdate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/exists.html">exists</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/fetchMode.html">fetchMode</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/find.html">find</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findAll.html">findAll</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findAllBy.html">findAllBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findAllWhere.html">findAllWhere</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findBy.html">findBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findOrCreateBy.html">findOrCreateBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findOrCreateWhere.html">findOrCreateWhere</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findOrSaveBy.html">findOrSaveBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findOrSaveWhere.html">findOrSaveWhere</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/findWhere.html">findWhere</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/first.html">first</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/get.html">get</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/getAll.html">getAll</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/getDirtyPropertyNames.html">getDirtyPropertyNames</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/getPersistentValue.html">getPersistentValue</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/hasErrors.html">hasErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/hasMany.html">hasMany</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/hasOne.html">hasOne</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/ident.html">ident</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/instanceOf.html">instanceOf</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/isAttached.html">isAttached</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/isDirty.html">isDirty</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/last.html">last</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/list.html">list</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/listOrderBy.html">listOrderBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/load.html">load</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/lock.html">lock</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/mapWith.html">mapWith</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/mappedBy.html">mappedBy</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/mapping.html">mapping</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/merge.html">merge</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/namedQueries.html">namedQueries</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/properties.html">properties</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/read.html">read</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/refresh.html">refresh</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/removeFrom.html">removeFrom</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/save.html">save</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/transients.html">transients</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/validate.html">validate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/where.html">where</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/whereAny.html">whereAny</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/withCriteria.html">withCriteria</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/withNewSession.html">withNewSession</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/withSession.html">withSession</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Domain%20Classes/withTransaction.html">withTransaction</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Plug-ins</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Plug-ins/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/URL%20mappings.html">URL mappings</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/codecs.html">codecs</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/controllers.html">controllers</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/core.html">core</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/dataSource.html">dataSource</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/domainClasses.html">domainClasses</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/hibernate.html">hibernate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/i18n.html">i18n</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/logging.html">logging</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/scaffolding.html">scaffolding</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/services.html">services</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Plug-ins/servlets.html">servlets</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Services</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Services/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Services/scope.html">scope</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Services/transactional.html">transactional</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Servlet API</h1><div class="menu-sub">
                        
                            
                            <div class="menu-item"><a href="../../ref/Servlet%20API/request.html">request</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Servlet%20API/response.html">response</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Servlet%20API/servletContext.html">servletContext</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Servlet%20API/session.html">session</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Tag Libraries</h1><div class="menu-sub">
                        
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/Usage.html">Usage</a></div>
                            
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/actionName.html">actionName</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/controllerName.html">controllerName</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/flash.html">flash</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/pageScope.html">pageScope</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/params.html">params</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/request.html">request</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/response.html">response</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/servletContext.html">servletContext</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tag%20Libraries/session.html">session</a>
                            </div>
                            
                            </div>
                    </div>
                    
                    <div class="menu-block"><h1 class="menu-title" onclick="toggleRef(this.parentNode.childNodes[1])">Tags</h1><div class="menu-sub">
                        
                            
                            <div class="menu-item"><a href="../../ref/Tags/actionSubmit.html">actionSubmit</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/actionSubmitImage.html">actionSubmitImage</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/applyLayout.html">applyLayout</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/checkBox.html">checkBox</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/collect.html">collect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/cookie.html">cookie</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/country.html">country</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/countrySelect.html">countrySelect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/createLink.html">createLink</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/createLinkTo.html">createLinkTo</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/currencySelect.html">currencySelect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/datePicker.html">datePicker</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/each.html">each</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/eachError.html">eachError</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/else.html">else</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/elseif.html">elseif</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/external.html">external</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/field.html">field</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/fieldError.html">fieldError</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/fieldValue.html">fieldValue</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/findAll.html">findAll</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/form.html">form</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/formatBoolean.html">formatBoolean</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/formatDate.html">formatDate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/formatNumber.html">formatNumber</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/grep.html">grep</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/hasErrors.html">hasErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/header.html">header</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/hiddenField.html">hiddenField</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/if.html">if</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/img.html">img</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/include.html">include</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/isAvailable.html">isAvailable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/isNotAvailable.html">isNotAvailable</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/javascript.html">javascript</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/join.html">join</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/layoutBody.html">layoutBody</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/layoutHead.html">layoutHead</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/layoutTitle.html">layoutTitle</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/link.html">link</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/localeSelect.html">localeSelect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/message.html">message</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/meta.html">meta</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/pageProperty.html">pageProperty</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/paginate.html">paginate</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/passwordField.html">passwordField</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/radio.html">radio</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/radioGroup.html">radioGroup</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/render.html">render</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/renderErrors.html">renderErrors</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/resource.html">resource</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/select.html">select</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/set.html">set</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/sortableColumn.html">sortableColumn</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/submitButton.html">submitButton</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/textArea.html">textArea</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/textField.html">textField</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/timeZoneSelect.html">timeZoneSelect</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/unless.html">unless</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/uploadForm.html">uploadForm</a>
                            </div>
                            
                            <div class="menu-item"><a href="../../ref/Tags/while.html">while</a>
                            </div>
                            
                            </div>
                    </div>
                    
                </div>
            </div>
        </td>
    </tr>
</table>

<div id="footer">
    Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
    
</div>

<script type="text/javascript" src="../js/docs.js"></script>

</body>
</html>
